The cd command (short for "change directory") is used to change the current working directory in Unix/Linux systems. It allows users to navigate the file system from the command line.
cd [directory]
cd /home/user/documentscd or cd ~cd ..cd -cd ../../projects$ pwd
/home/user
$ cd Downloads
$ pwd
/home/user/Downloads
pwd to print the current directory before and after using cd.The cd command in Linux stands for “change directory.” It is one of the most basic and frequently used commands in any Unix-based system, including Linux distributions like Ubuntu, Fedora, Debian, and Arch Linux. This command allows users to navigate the file system by changing their current working directory.
cd [directory]
Here, [directory] is the path to the directory you want to move to. This can be either an absolute path or a relative path.
cd /home/username/Documentscd ..cd ~ or simply cdcd -cd ../DownloadsAn absolute path starts from the root (/) and shows the full path to the destination. A relative path starts from the current directory.
cd /var/logcd ../../myfolder~ – Represents the home directory.. – Refers to the parent directory. – Refers to the current directory- – Switches to the previous directorypwd before and after cd to verify your current location..bashrc file.You can use environment variables with the cd command. For example:
cd $HOME
cd $OLDPWD
If the directory doesn't exist or you mistype the name, Linux will return an error such as:
bash: cd: foldername: No such file or directory
In shell scripts, cd is used to navigate to working directories before executing commands or compiling files.
#!/bin/bash
cd /path/to/project
make all
Use cd in a chain of commands:
cd /var/www && ls
This changes to the directory and lists its contents.
rm.The cd command is essential for navigating the Linux filesystem. It’s simple yet incredibly powerful when combined with relative paths, aliases, and scripts. Mastering cd is a foundational skill for anyone working in Linux environments.
The cd command in Linux stands for “change directory.” It is one of the most basic and frequently used commands in any Unix-based system, including Linux distributions like Ubuntu, Fedora, Debian, and Arch Linux. This command allows users to navigate the file system by changing their current working directory.
cd [directory]
Here, [directory] is the path to the directory you want to move to. This can be either an absolute path or a relative path.
cd /home/username/Documentscd ..cd ~ or simply cdcd -cd ../DownloadsAn absolute path starts from the root (/) and shows the full path to the destination. A relative path starts from the current directory.
cd /var/logcd ../../myfolder~ – Represents the home directory.. – Refers to the parent directory. – Refers to the current directory- – Switches to the previous directorypwd before and after cd to verify your current location..bashrc file.You can use environment variables with the cd command. For example:
cd $HOME
cd $OLDPWD
If the directory doesn't exist or you mistype the name, Linux will return an error such as:
bash: cd: foldername: No such file or directory
In shell scripts, cd is used to navigate to working directories before executing commands or compiling files.
#!/bin/bash
cd /path/to/project
make all
Use cd in a chain of commands:
cd /var/www && ls
This changes to the directory and lists its contents.
rm.Users can enhance their workflow by creating symbolic links to frequently accessed directories or using alias:
alias proj='cd /home/user/myproject'
This saves time when navigating deeply nested directories.
Ctrl+R to reverse search your terminal history and reuse old cd commands.pushd and popd for stack-based directory navigation.While cd behaves similarly across shells like Bash, Zsh, and Fish, some enhancements exist:
It will take you to your home directory.
Yes, use quotes or escape the space: cd "My Folder" or cd My\ Folder
Use cd - to switch back to the previous directory.
The cd command is one of the cornerstones of Linux file navigation. Understanding its options, shortcuts, and behavior across shells helps streamline development and system administration tasks. Practice it alongside commands like ls, pwd, and mkdir for effective command-line mastery.