Skip to content

Latest commit

 

History

History
100 lines (65 loc) · 1.54 KB

File metadata and controls

100 lines (65 loc) · 1.54 KB

cd

The cd (change directory) command is used to navigate between directories in a Linux filesystem.

Basic Usage

  • Syntax:

    cd [directory]
  • Examples:

    cd /home/user/documents
    • Changes the current directory to /home/user/documents.
    cd ..
    • Moves up one directory level (to the parent directory).
    cd ~
    • Changes to the home directory of the current user.
    cd -
    • Switches to the previous directory you were in.
    cd /
    • Changes to the root directory.

Options

The cd command itself doesn’t have options, but it works with special characters:

  • . (dot):

    • Refers to the current directory.
    cd .
    • No change in directory; stays in the current directory.
  • .. (double dot):

    • Refers to the parent directory.
    cd ..
    • Moves to the parent directory.
  • ~ (tilde):

    • Represents the home directory of the current user.
    cd ~
    • Moves to the home directory.
  • - (dash):

    • Switches to the previous directory.
    cd -

Quick Tips

  • No Argument (cd):

    • Running cd without any arguments takes you directly to your home directory:
    cd
  • Absolute vs. Relative Path:

    • You can use absolute paths (starting from /) or relative paths (starting from the current directory) with cd.

      cd /usr/local/bin   # Absolute path
      cd ../bin           # Relative path