To move around the Linux filesystem, you'll use paths to specify your destination. The primary tool for this is the cd (change directory) command. Understanding how to use this cd linux command is a fundamental skill for working in the terminal or cd command prompt.
Understanding Paths
There are two ways to specify a path: absolute and relative.
-
Absolute Path: This is the full path starting from the root directory (
/). The root is the top-level directory in the filesystem. Any path that begins with/is an absolute path. For example:/home/pete/Desktop. -
Relative Path: This path is relative to your current location in the filesystem. If you are in
/home/pete/Documentsand want to access a subdirectory namedtaxes, you don't need the full path. You can simply use the relative path:taxes/.
Using the cd Command
Once you understand paths, you can use the cd command to change your current directory. Whether you're in a Linux terminal or a Windows cd command cmd prompt, the concept of changing directories is universal, though the syntax may differ slightly.
To change to a specific directory using an absolute path, you would type:
cd /home/pete/Pictures
This command moves you directly to the Pictures directory.
Navigating to a cd folder
If you are already in a directory and want to move to a sub-directory, you can use a relative path. For instance, if your current location is /home/pete/Pictures and it contains a cd folder named Hawaii, you can navigate into it with:
cd Hawaii
Notice we only used the folder's name. This is because we were already in its parent directory, /home/pete/Pictures.
Essential Navigation Shortcuts
Navigating with full paths can be tedious. Fortunately, the shell provides several shortcuts to make moving around much faster.
.(current directory): Represents the directory you are currently in...(parent directory): Moves you one level up to the directory containing your current one.~(home directory): A shortcut to your personal home directory, like/home/pete.-(previous directory): Takes you back to the last directory you were in.
You can use these shortcuts with the cd command:
cd .
cd ..
cd ~
cd -
Experiment with these shortcuts to become more efficient on the command line.