Home > Articles

  • Print
  • + Share This

Changing Directories with the cd Command

Use the cd (change directory) command to navigate through the Linux file system's directories. Use this command with a directory specification or pathname to move to a specified directory. This command is built in to each Linux shell, and can also be used as a shortcut to quickly move back to your home directory.

$ pwd 
/home/michael 
$ cd /usr/bin 
$ pwd 
/usr/bin 
$ cd 
/home/michael 

If you enter the cd command by itself, you'll return to your home directory (specified in the $HOME environment variable). Move up to the next directory by entering two periods and a forward slash (../) with the cd command, like so:

$ pwd 
/home/michael 
$ cd ../ 
$ pwd 
/home 

The two periods represent the parent directory. Using a single period represents the current directory, but is not useful for navigating the directory structure. A hyphen, however, can be used as a quick navigation tool:

$ pwd 
/home/michael 
$ cd /usr/local/bin 
$ cd - 
$ pwd 
/home/michael 

Use a hyphen with the cd command to quickly navigate between the two most recently visited directories (in the previous example, I navigated from my home directory to the /usr/local/bin directory and then back to my home directory). Use the tab key on the command line to change directories without typing a full pathname:

$ cd /usr/loc[tab] 
returns 
$ cd /usr/local/ 

Use this approach to save typing and time when navigating to known directories. When you press the tab key, it will complete the directory or filename if it finds only one option that matches what you've typed. If it finds none or more than one match, the terminal will beep. Pressing tab again yields a list of possible matches (if there are any).

$ cd /usr/l[tab] 
lib    libexec    local 
$ cd /usr/l 
  • + Share This
  • 🔖 Save To Your Account

Related Resources

There are currently no related titles. Please check back later.