Table of Contents

    The ‘cd‘ command in Linux stands for “change directory.” It is a command used to navigate through the file system by switching between directories. By entering “cd” followed by the name of the directory, you can move from one location to another within the Linux file structure. Additionally, using certain options with ‘cd‘ allows for more advanced navigation, such as moving to the home directory or the previous directory. Mastering the ‘cd’ command is essential for any Linux user.

    You can click here to learn more about Linux Filesystem and Directory Structure before dive into cd command.

    Absolute directory references

    Using absolute directory references means providing a complete path from the root directory to a specific directory or file. In the context of the ‘cd’ command, this involves specifying the entire path starting from the root directory (“/“).

    For instance, if you want to change to the “Documents” directory within the “user” directory, you would use the absolute path like this:

    To be more clear, you can display the location via shell command. Use the pwd command. This command displays the absolute path of the current working directory. It is useful to determine your current location within the file system. pwd stands for “print working directory.

    Let’s do another example: we will changes the current working directory to “/home/tim/Templates” It means you’re navigating to the “Templates” directory inside the “tim” user’s home directory. After that, running ‘pwd‘ will print the current working directory.

    Relative directory references

    Relative directory references in Linux involve specifying the path to a directory relative to the current working directory. Instead of providing the complete path from the root directory (“/”), you indicate the path starting from your current location in the file system.

    For example, if your current working directory is “/home/tim/” and you want to navigate to the “Documents” directory, which is a subdirectory of your current location, you can just do like this

    Here is a tip for you :

    • Use single dot (.) to refer the current directory
    • use double dot (..) to refer to the parent directory

    In this example, if you are in “/home/tim/Documents” and you want to refer to the current directory, you can use:

    This example using double dot. If you are in “/home/tim/Documents” and you want to move up one level to “/home/tim,” you can use

    Note that use can use either cd .. or cd ../

    Use can also go to two level up, use ../../ refers the parent of the parent directory, see example below:

    The example use cd ../../ to moved up two levels in the directory structure, transitioning from “/home/tim/Test1/SubFolder 3” to “/home/tim

    Summary

    In conclusion, mastering the ‘cd‘ command in Linux opens a gateway to seamless directory navigation. Whether using absolute paths or relative path, choosing the appropriate method based on the task at hand is crucial for effective directory navigation. Also, it is a good habit to use pwd command to verify your current location.

    More Resources

    How to Change the Directory in Linux | cd Command

    10 Useful cd command tips in Linux

    Leave a Reply

    Your email address will not be published. Required fields are marked *