Navigating a file system

Navigating a filesystem is one of the most important things you can do in the Linux command line. There is only one command you need to know in order to move from one directory to another- cd, but as with anything in Linux, there are hidden intricacies (as you’ll see in the examples).

cd stands for “change directory”. cd accepts one argument which is the name of the directory you want to change to. Imagine it like double-clicking on a folder in a graphical interface.

Examples

cd Documents will put you in the Documents directory

cd .. will move you up a directory. .. is command line speak for “parent directory”.

In the same vein as the last example, cd ../Downloads will move you up to the parent directory and then back down into the Downloads directory, which is a sibling of the directory you were in when you ran the command.

cd ~ or cd will put you in your home directory. The tilde (~) character is translated to your home directory. Also, running cd without an argument will just put you back in your home directory.

cd / will put you in the root of the file system. Imagine the filesystem like a tree, / is the start of the tree.

cd /etc (note the leading /) will put you in the etc directory immediately below the root of the filesystem.

Using more qualified paths as the argument to cd will make navigating quicker, but it does take a bit of understanding of the basic layout of the file system.

Imagine you’re in your home directory, typing…

cd /var/www

… is quicker than typing…

cd ..
cd ..
cd var
cd www

… and you end up in the exact same place with either method.