How to use the cd command on Linux

August 31, 2021

How to use the cd command on Linux

In this post, we will see how to use the cd command, one of the most important Linux commands, which serves to move between directories.

How to use the cd command capa

What is the cd command for?

With the cd command, the user can move between directories.

There is the possibility to move with the full path or also directory by directory.

This is one of the most important commands in Linux, which gives freedom and agility to move between directories.

Let’s now see the main uses of the cd command.

obs: These commands were all previously tested on the Ubuntu distribution.

Moving between directories:

cd /var/log/

cd apache2 (dentro de /var/log)

In the first example, we change to the log directory which is inside var, as we added the slash at the beginning we came from the system root directory.

In the second example, we were in /var/log and went to apache2, apache’s log directory that is inside the log, but we didn’t start from the root, but from the current folder.

Return to the previous directory:

cd —

With the option — we go back to the previous directory from the current one.

For example, we were in / and we went to var (cd /var/).

If we use cd — we’ll go back to /

Up a directory / Back a directory:

We can go back to the parent directory with the following command.

cd ..

So if we are in /home/ and we use cd ..  we will go back to /, which is the parent directory of /home/.

Another variation of uploading directories is that we can do it as many times as we want, for example uploading 2 directories.

cd ../../

This can be rolled up to as many directories as we need by adding ../ to the end of the command.

Go to current user home:

cd ~

Using cd with ~ we can move directly to the user’s home, for example, /home/matheus.

Cd Command Conclusion

In this post, we saw important uses of the cd, which will probably enter your daily life if you use Linux.

Furthermore, we saw the importance and what the cd command is for.

And that’s it for today, until the next post!

Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x