What is the cd command & how to use it?

The cd is the command in Linux and Unix-like operating systems which stands for change directory. But, the only use of the cd is changing the directory from the current directory to the destination directory. So, this is an important command to switch between directories.

If you like to watch the cd command video then you can watch the video.

cd in Linux | Watch cd in the video.

How to get help with the cd command

I always suggest reading the manual page and help page. So, it will give you a deep introduction to the command.

And so, to get the manual page type the below command,

man 1p cd

But, to get the only command options, you can type the below command.

cd --help

Syntax of the cd command

As we know now, how to get some information about the cd command using the above command with arguments. So, now let’s talk about cd syntax. Also, the syntax of the cd command is mentioned below,

cd [option] directory….

Changing location from root home directory to /

If you want to check the current working directory then you can use the pwd command and to change the current working directory to / (root directory) then you can write like

cd /
cd command
The output of the cd command.

Changing location from anywhere to the home directory

If your working directory is any other directory and you want to come in your user home directory. So, you can just type the below command and it will bring you to your home directory. cd by itself or cd ~ will always put you in your home directory.

cd

OR

cd ~
cd command
Switching from anywhere to home.

Using cd ..

For example, I am in the /etc/ssh directory and I want to come back in the /etc directory then you can type

cd ..

As a result, you can see in the picture.

cd command-parent-directory
Switching to the parent directory of the current directory

Conclusion

In this article, you learned about the cd command and you can see that it is easy to use. So, I hope, you understand. But if you have any questions, you can ask in the comment section.

Also, you can find the below links useful.

Leave a Reply

Your email address will not be published.