How to Use cd Command in Linux?

Posted in

How to Use cd Command in Linux?
maazbinasad

Maaz Bin Asad
Last updated on July 13, 2024

    Moving across different directories can be a frequent operation while working with Linux. You may need to move forward in some directory or even go to the root directory of your system. All the tasks that require you to move across different directories can be handled by using the cd command in Linux. This command is shorthand for “change directory”. In this article, we will discuss various options available to use with the cd command. Also, we share some examples that will help you understand exactly how the cd command works in a Linux terminal .

    What is the cd Command?

    This command is used to change the current working directory and navigate either forward or backward in the file system. Moving forward means we are going into some directory that is present within the current directory. On the other hand, moving backwards means we are going to the parent directory of the current directory.

    Most Popular cd Commands

    • Move forward

    If you want to navigate into a subdirectory, you can use the following command:

    cd <directory>
    • Move backwards

    To navigate into the parent directory or to the directory one level up to the current directory, you need to run the following command:

    cd ..
    • Switching to the root directory

    In case you don’t know, the root directory is the first directory in your system hierarchy. To navigate to the root directory from any directory, you need to execute the following cd command:

    cd /
    • To navigate into subdirectories of subdirectories

    You can go multiple levels down into the file system with a single cd command which is mentioned below:

    cd dir1/dir2
    • Go to the home directory of your system

    There is a cd command that allows you to navigate directly to the HOME directory of your Linux file system and is as follows:

    cd ~

    Conclusion

    In this article, we discussed various options that you can use with the cd command. The cd command is primarily used to switch between different directories of your file system. You can move one or more levels up or down in your file system hierarchy by using different cd commands. Also, you can directly navigate to the root or home directory by using the cd command with appropriate options. People are also reading:

    Leave a Comment on this Post

    0 Comments