Linux Tutorial

Linux File/Directory Management

Linux Packaging And Compression

Vim Text Editor

Linux Text Processing

Linux Software Installation

Linux User/User Group Management

Linux Permission Management

Linux Filesystem Management

Linux Advanced Filesystem Management

Linux System Management

Linux Backup and Recovery

Linux System Service Management

Linux System Log Management

Linux Boot Management

LAMP/LNMP Environment

SELinux Management

Linux cd Command: Change Directory

The cd command in Linux (short for "change directory") is a built-in shell command used to navigate between directories in the file system. In this tutorial, we will discuss how to use the cd command effectively, along with various options and examples.

  1. Basic usage of the cd command:

    To change to a specific directory, use the cd command followed by the path of the directory:

    cd /path/to/directory
    

    This command will change the current working directory to the specified directory.

  2. Navigating to the home directory:

    To quickly navigate to your home directory, you can use the cd command without any arguments or with the ~ character:

    cd
    

    or

    cd ~
    

    Both commands will change the current working directory to your home directory.

  3. Navigating to the parent directory:

    To navigate to the parent directory of the current working directory, use the .. notation:

    cd ..
    

    This command will change the current working directory to its parent directory.

  4. Navigating to the previous working directory:

    To navigate back to the previous working directory, use the - character:

    cd -
    

    This command will change the current working directory to the previous working directory and display the path of the new working directory.

  5. Navigating using absolute and relative paths:

    • Absolute paths: An absolute path starts with a / and represents the full path of the directory. For example:

      cd /usr/local/bin
      
    • Relative paths: A relative path is a path relative to the current working directory. For example:

      cd Documents/Work
      

      This command assumes that there is a Work directory inside the Documents directory, which is a subdirectory of the current working directory.

By following this tutorial, you should now have a good understanding of how to use the cd command in Linux to navigate between directories in the file system. The cd command is a fundamental command for working with the file system and is essential for efficient command-line navigation.

  1. How to use cd command in Linux:

    • Change the current working directory using the cd command.
    cd directory_name
    
  2. Changing directories in the terminal with cd:

    • Navigate to a specified directory.
    cd /path/to/directory
    
  3. Navigating the file system using cd in Linux:

    • Move through the file system using cd.
    cd /parent_directory/child_directory
    
  4. Relative vs. absolute paths with cd command:

    • Use either relative or absolute paths with cd.
    cd ../relative_directory
    
  5. Moving up one directory with cd ..:

    • Go up one level in the directory hierarchy.
    cd ..
    
  6. Using wildcards with cd in Linux:

    • Utilize wildcards for directory navigation.
    cd /path/to/di*rectory
    
  7. Creating and navigating through directories with cd:

    • Create a directory and move into it in a single command.
    cd new_directory && mkdir new_directory
    
  8. cd command shortcuts and tips:

    • Employ shortcuts for efficient directory changes.
    cd -  # Return to the previous directory
    
  9. Changing to the home directory with cd ~:

    • Quickly switch to the user's home directory.
    cd ~