The cd
command in Linux stands for change directory. It is used to change the current directory of the terminal. The terminal, by default, opens the home directory.
The cd
command comes as part of the GNU Core Utilities, available on all Unix-like operating systems.
For this shot, we will use the
ls
command to list all folders within the current directory.
The cd
command accepts several types of arguments. We will go through the most frequently used ones in this shot.
To go to the root directory, we input /
as the argument.
We do not provide any arguments to the cd
command to go to the home directory.
To shift one level above the current directory, we input ..
as the argument.
To go to the previous directory, we use -
as our argument.
For custom navigation across any directory, we can send its path as the argument.
The following example demonstrates how to use the cd
commands and their different arguments in terminal.
First, we use the ls
command to list all the folders in the home directory. Subsequently, we use the cd
command to go to the bin
folder and list all the folders in bin
.
We shift one level above using the cd ..
command and are back in the home directory as confirmed using the ls
command. Using cd
with no arguments, we go to the root
folder.