In this article i will cover and instruct you in depth about a very known command i.e. cd (change directory) .
What is cd command ?
This cd command is the first command you must have heard and used while started with Liunx/Unix system. This is a very often and widely used common command while working in.
This cd command helps you to move around in the file system.
Use Of cd Command
In cd command One dot ‘.’ represents the current working directory while two dots ‘..’ represent the parent directory.
When cd is invoked with ‘..’ it takes you to one directory up.
Suppose Below is your current directory
[email protected]:~/Desktop/cloud$ pwd (current working directory) output /home/tcd/Desktop/cloud (current working directory)
Now lets run cd with ‘..’
[email protected]:~/Desktop/cloud$ cd .. Output [email protected]:~/Desktop$
“ cd -” will return you to the previous directory. It works like undo.
This is the path with respect to root (/) directory. The / means that you start at the top level directory and continue down.
For example to get to /home/user1/Desktop you would have to run the below command.
$ cd /home/user1/Desktop
This is an absolute path because you started at the top of the hierarchy and go downwards from there.
This is the path with respect to current directory. Use a relative path when you start from a directory below the top level directory structure. This is dependent on where you are in the filesystem.
For Example if you are in root’s home directory and want to get to /root/home/Desktop, you type:
$ cd Desktop
Please note that you can not use / in the above command. If you use a / it would cause this to be an absolute path, working from the top of the hierarchy downward.
Switch to previous working directory quickly
This cd utility have a very good feature, that helps you switching between directories. And you can quickly switch to your previous working directory by invoking the command cd – or cd..
Now let us consider you are at Sub-directory inside Desktop directory, and to wanted to land on Desktop invoke the below command.
$ cd .. or cd-
For example : I am at tcd directory inside Desktop ad wanted to go back to Desktop
Switch to home directory quickly
When you invoke cd command with tilde (~) it will land you on the home directory quickly. Use the below command to do so. Other way is there you can navigate to home directory if you invoke this command alone without any other keyword it will throw you on Home directory.
$ cd ~
For example: check the screenshot.
In this article i have covered almost all the basic understanding of this command. By which you will be able to work with cd command easily.
More suggestions : Click here