How to Use the CD Command in Linux

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 command:

$ cd [DIRECTORY...]
Go to immediate parent directory
cd ..

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 immediate parent
Go to previous directory
cd -

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 previous dir
Go to home directory
cd ~

The 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.

go to home dir
Move two directories up from current location
cd ../../

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.

move 2 dir up
Go to directory with spaces in their name
cd directory\ name\ with\ space


cd 'directory name with space'

To 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 ('').

Example: To cd into the "Example 3" directory, you can use either cd Example\ 3 or cd 'Example 3'.

go to dir with space in name