What Is the cd Command in Linux?
The cd command is one of the basic Linux command lines. It is important to master the skills of using the cd command in Linux because it helps you change directories in Linux. To be specific, you can run the cd command to navigate to or switch to the needed path, folders, or directory. After that, you can run other command lines to make further operations.
In this article, NewsPivot will walk you through when and how to use the cd command in Linux in different situations.
How to Use the cd Command in Linux?
In this part, we will introduce some common sceneries when you can use the cd command in Linux.
How to Open the Terminal in Linux?
If you want to run special command lines like the cd command in Linux, you first need to access the terminal.
It is easy to do this.
Step 1. Click the Show Apps icon on the bottom-left corner of the screen.
Step 2. Find the Terminal icon and click it to open it. However, if there are so many apps in the list, you can type terminal into the top search bar to directly locate the terminal and then click it to open it.
#1. cd directory
The cd directory command is used to go to the desired directory that you want to operate on. You should replace directory with the target directory name.
For example, if you want to navigate to the Documents directory, you can type cd Documents and press Enter. Then, you can discover that the Documents directory is selected.
If you want to check the files in the Downloads folder, you can first run cd Downloads in the terminal to select this directory and then run ls to list the filenames in that folder.
#2. cd /
The cd / command is used to switch to the current directory to the root directory, which is the first directory in your filesystem hierarchy. This command is useful when you don’t need to make any operations on the current one.
#3. cd directory1/directory2/directory3
The cd directory1/directory2/directory3 is used to go to a directory from a directory. You need to replace cd directory1/directory2/directory3 with the subdirectory name or location you want to move in.
For example, if I want to navigate to the Downloads directory, I can also run cd /home/stella/Downloads in the terminal.
#4. cd ~
The cd ~ command is used to change the directory to the home directory no matter which directory you are currently in. After running the cd ~ command, you can run pwd to check which directory you are in now.
Alternatively, you can also just run the cd command to switch to the home directory. After running the cd command, you can run pwd to check which directory you are in now.
#5. cd ..
The cd .. command can help you switch to the parent directory of the current directory, or the directory one level up from the current directory. So, “..” in this command represents the parent directory.
Bottom Line
These are the commonly used cd command lines in Linux. Remember that the cd command line is important among various Linux command lines. Just try it if you need to run it in the terminal in Linux.