Linux cd Command
cd stands for Change Directory. It changes the current working directory.
Syntax of cd command :
$ cd <dirname>
Example of cd command:
This is an important command. With the help of this command you can move all over your directories in operating system. You can go to your previous directory or previous to previous directory, or anywhere.
There are two types of cd or change directory option
There are :
- Absolute path
- Relative path
Change from current directory two away
# cd <absolute path>
# cd <relative path>
Linux Absolute and Relative Paths
The absolute path is the complete path of a directory. For example, we’re in /home/infolinux directory. Lets assume there is a directory named Desktop here. If we want to change the directory to desktop. Then using absolute path, we’ve to use cd /home/infolinx/Desktop. However, if we want to use relative path, then we can simply cd Desktop/.
If you starting with a back slash ( / ) sign. The root of the file is assumed. So you don’t put back slash ( / ) sign. The current directory is assumed to be the starting point.
In below example, we’re at /home/test. Here you want to go the home directory. If you type cd /home. Then you go to the home directory.
Example of the concept of Absolute and Relative Paths
Use Absolute Path:
Using Relative Path:
Some cd option are shown below:
- ( cd ~) ~ stands for home directory
- ( cd .) . stands for the current directory
- ( cd ..) .. stands for parent directory
- ( cd /) / It takes you to the system’s root directory.