The cd
command in Linux is used to change the current working directory in the terminal. It allows you to navigate through different directories and access the files and subdirectories within them. The basic syntax of the cd
command is:
cd [directory_path]
Here are a few examples to illustrate the usage of the cd
command:
- Changing to a Specific Directory:
cd /home/user/Documents
This command changes the current directory to the “Documents” directory within the “user” directory.
- Moving Up One Directory Level:
cd ..
This command moves you up one level in the directory hierarchy. For example, if you were in “/home/user/Documents,” running this command would take you to “/home/user.”
- Moving to the Home Directory:
cd ~
This command takes you to your home directory, which is typically “/home/username.”
- Using Relative Paths:
cd Pictures/Summer
If you’re in the “Documents” directory and you want to navigate to the “Summer” subdirectory within the “Pictures” directory, you can use a relative path.
- Using Tab Completion:
cd Downlo[TAB]
Typing the first few characters of a directory name and then pressing the “Tab” key will autocomplete the directory name if it’s unique, making navigation faster.
- Using Variables:
cd $HOME
The $HOME
variable refers to your home directory, so this command takes you to your home directory regardless of your current location.
- Using Absolute Paths:
cd /var/log
Absolute paths start from the root directory (“/”) and provide a direct way to navigate to a specific location.
- Using Special Directories:
cd -
This command takes you to the previous directory you were in. It’s useful for quickly toggling between two directories.
Remember that Linux is case-sensitive, so directory names must be entered exactly as they appear. The cd
command is an essential tool for navigating the file system and is an integral part of using the Linux command line effectively.