Skip to content

Cd command linux guide

Command definition

The cd command, short for "change directory," is a fundamental command in Linux and Unix-like operating systems that allows users to navigate between different directories in the file system. By using cd, users can move into a specified directory, return to the previous directory, or go back to their home directory, facilitating easy access to files and folders.

Usage examples

  1. Change to a specific directory: This command allows you to navigate directly to a specified directory. bash cd myfolder

  2. Change to a parent directory: This command moves you up one level in the directory hierarchy. bash cd ..

  3. Change to the home directory: This command quickly takes you back to your home directory from anywhere in the file system. bash cd ~

  4. Change to a directory using an absolute path: This command allows you to navigate to a directory using its full path. bash cd /home/user/myfolder

  5. Change to a directory using a relative path: This command enables you to navigate to a directory relative to your current location. bash cd ../myfolder

  6. Change to the previous directory: This command allows you to switch back to the last directory you were in. bash cd -

  7. Change to a directory with spaces in its name: This command demonstrates how to navigate to a directory with spaces by using quotes. bash cd "my folder"

  8. Change to a directory using tab completion: This command shows how to use tab completion to quickly navigate to a directory without typing the full name. bash cd myf<TAB>

  9. Change to a directory using environment variables: This command allows you to use environment variables to navigate to a directory. bash cd $HOME/myfolder

  10. Change to a directory with a symbolic link: This command shows how to navigate to a directory using a symbolic link. bash cd symlink_to_myfolder