cd
stands for change directory
this tells your shell prompt to switch the current working directory to a new directory. To understand how it works, we’ll need to take a small deviation to learn about the important abbreviations for any Unix system. Anytime that you begin to tell Unix about a filepath, the first character you type is very important to what you are telling Unix.
.
means the current directory I am in (or the current working directory)
..
is the parent directory, that is, the directory above this one
~
means my home directory
/
is the root of my hard drive
(none of the above) … that is, simply a folder or file name is what we call a relative path, and means the current directory I am in (also known as the or the current working directory). This is actually just like .
(single period). In some cases, it makes more sense to specify the .
. Typically, when you are navigating in Unix, you can leave it off and trust the shell prompt will interpret your input as relative to the current directory (hence, “relative path”).
The first character of how you specify your pathname determines how the system will interpret what you say. If you begin it with .
you mean “from the current directory.” If you begin your path with ..
you are saying “from the parent directory.”
If you begin it with a ~
you typically mean from my home directory. Your home directory is typically set up for you by the operating system. On my Mac, for example, my home directory is in /Users/jason
. When I say ~
that means /Users/jason
(on your system, of course, it will mean your home directory.)
If you begin your filepath/
(on the shell prompt) that refers to the root of your hard drive.
When you cd
, you are changing the directory of your current working directory for that shell prompt to a new one. The new one might be relative to the CWD (as in the case with a relative path like .
or ..
) or it might be non-relative (as in the case with ~
and /
). Either way, your current working directory will be changed. That’s why we call this, change directory or cd
for short.