System navigation is one of the most basic tasks that a user can perform on an operating system. While many file managers are available that allow you to switch directories and navigate your disk drives in a graphical way, doing the same using the command line can provide you better control over your system.

Luckily, Linux provides you with a command known as cd, which allows you to easily change the current working directory on your terminal.

Here's how you can use the cd command on Linux, the only utility that you'll ever need to traverse through directories on your system storage.

How to Use the cd Command in Linux

The cd command stands for Change Directory. One of the most fundamental commands in Linux, cd has become a global command for switching directories. Some other implementations of the command such as chdir, used in MS-DOS systems, are also present.

Basic Syntax

The basic syntax of the cd command is:

        cd [options] [path]
    

...where options are the arguments passed with the command and path is the absolute or relative path to the directory.

Absolute and Relative Pathnames

Before you can use the cd command to its full extent, you must know the difference between absolute and relative pathnames. The absolute pathname is the complete path to the directory, starting from the / (root) folder.

On the other hand, the relative pathname is derived from the current working directory. You can move up and down the directory tree efficiently with the cd command if you're well-versed on relative paths.

For example, if your current working directory is /home, and you want to change the directory to /Desktop. Then, using the absolute pathname:

        cd /home/username/Desktop
    

On the other hand, if you want to switch to the /Desktop directory using a relative path, all you have to type is:

        cd /Desktop
    

Cd keeps track of what directories are above and below the current directory, to allow a user to quickly shift to other directories without having to type the whole pathname.

If you don't know the exact name of the subfolder that you want to switch to, use the ls command to list down every directory in that folder.

Switch to the Home Directory

On a Linux system, the /home directory is a special directory reserved for a user's personal files, programs, and subfolders. When you log in to your system, the home directory is set as the current working directory by default.

The home directory has a special character assigned to it---the ~ (tilde) character. Instead of specifying the complete path to your home directory (/home/username), you can just pass the ~ character with the cd command to change the current working directory to /home.

        cd ~
    

Similarly, you can navigate to other user's home directory as follows.

        cd ~username
    

Related: How to List All Users in Linux

In the previous section, we switched the present working directory to /Desktop. In the command, you can use the ~ character to denote the /home directory and strip down the command to half of its size.

        cd ~/Desktop
    

Just like the home directory, the / character denotes the /root directory on a Linux-based operating system. To switch to the root folder anytime:

        cd /
    

Change to the Previous Working Directory

If you're working with multiple directories at a time, you can easily switch back and forth to the previous working directory using the - (hyphen) character.

For example, if the current working directory is /home and you switch to the /root directory. Then, /root will become the current working directory, and /home will be the previous working directory.

Typing the following command will take you to the previous directory i.e. /home.

        cd -
    

Also, issuing the cd command followed by a space character will take the user to the previous working directory.

        cd 
    

Switch to the Parent Directory

The directory which consists of one or more sub-directories is known as the parent directory. Simply put, if you have /Desktop and /Downloads folders in your /home directory, then the /home directory will be the parent directory for /Desktop and /Downloads.

The .. and . characters stand for the parent directory and the current directory respectively.

Use the double dots character (..) to switch to the parent directory.

        cd ..
    

The aforementioned command will take you one level up the directory tree. You can also pass additional .. characters to move further up the directory tree.

To move two levels above your current working directory:

        cd ../../
    

You can also pass a specific directory one level above the present working directory.

        cd ../Folder
    

Change to a Directory Name With Spaces

Not every folder on your system will have a one-word name. Some of them might include the space character. For example, /home/username/Important Documents.

In such situations, specifying the directory name will return an error.

        cd /Important Documents
    

Output:

        bash: cd: too many arguments
    

To switch to directories that have spaces in the name, wrap the pathname in quotes as follows. Note that you can use both single and double quotes in the command.

        cd 'Important Documents'
cd "Important Documents"

Alternatively, you can use the backward slash (\) character to escape the spaces.

        cd Important\ Documents
    

Related: How to Get Started Using Linux

System Navigation Through the Command Line

The Linux terminal is a powerful text interface for controlling the working of your computer. You can carry out almost any task using the command line. Changing directories, copying files and folders remotely, listing file information, editing configuration files, you name it. There's a command for everything that you want to do on Linux.

However, there's a drawback to having so many commands. Not everyone can learn and memorize the commands, not to mention the hefty amount that's available to use in the first place. But as a beginner Linux user, you won't be using all of the utilities that are available on your system.

Instead, learning some basic commands that will help you in performing fundamental operations is more than enough to get started with the operating system.