Short code for Change Directory the
cd command is use to switch from current directory to other directory in the operating system.
General syntax for
$ cd [DIRECTORY...]
Go to immediate parent directory
This command will get your from current directory to a directory before this.
Example: Getting from /Documents/dir_1/dir_2/ to /Documents/dir_1/.
Go to previous directory
This command will return you to the directory before the current. Think of it as the back button in your browser.
Example: If you navigate from /Documents/Example_1 to /Documents/Example_1/Example_2, the
cd - command will bring you back to Example_1/.
Go to home directory
cd ~ command will bring you back to your home directory, regardless of which directory you are currently in.
Example: It does not matter if you are inside /Documents/Example_1/Example_2, or /Documents/Example_1/, executing
cd ~ will bring you back to your home directory.
Move two directories up from current location
Instead of doing
cd .. twice to go up two directories before the current, you can use just
cd ../../ instead.
Example: If we are currently inside /Documents/Example_1/Example_2/. The command
cd ../../ will bring you directly to /Documents.
Go to directory with spaces in their name
cd directory\ name\ with\ space
cd 'directory name with space'
cd into directories with spaces in their name, you can either add left-backlash (
\) at the back each word, or wrap the directory name with single quotes (
cd into the "Example 3" directory, you can use either
cd Example\ 3 or
cd 'Example 3'.