How to change directory using cd command in Linux?

The cd command in Linux is used to change the current directory. cd is a shell builtin command.


cd [path]

 where path specifies the path of the new directory.

For example:

how to use cd command in linux

The current working directory as checked with pwd command was /home/baljit/search. Next, we  use cd to change the directory to /home/baljit/cse325

Different methods to use cd command in Linux

1. If no path is specified

When you use cd without giving any directory path then cd shifts to the home directory.

using cd without giving path

As shown above without using any path the directory is changed to home directory which in my case is /home/baljit.

2. Change to the Directory Above or the Parent Directory

Use cd .. (i.e., <cd><space><two dots>) to shift to the directory above.

For example, let us change the current directory from /home/baljit to /home/baljit/search and then finally to /home/baljit/search/K1801

using cd command in linux

Now, the current working directory is /home/baljit/search/K1801. If we use cd .. then it shift to the directory above which is /home/baljit/search. Again use cd .. and see the shift.

using cd command in linux

3. Shift to Home Directory

An alternate method to shift to home directory is the use of cd ~ (the tilde symbol. Remember to use space between cd and ~)

$cd ~

4. Change to most recent directory

Sometimes you want to change to the recent directory. But you don’t remember which was the recent one. Use the minus sign with cd.

$cd -

For example, let us suppose the current directory is /home/baljit/cse325. Next, we shift to /home/baljit/search/K1802. So, the current directory now is /home/baljit/search/K1802.

using cd - command in linux

Now, if you want to shift back to the most recent directory (/home/baljit/cse325), use cd –

More Examples of How to use cd command in Linux

Q1. What will happen if you use the command
$cd .
Ans: It will remain in the same directory because ‘.’ Means the current directory itself.

Q2. Is cd an internal or an external command?

Q3. What will happen with the command

$cd ../..

PPT on cd command

Video on cd command

Other Relevant Commands



One thought on “How to change directory using cd command in Linux?

Leave a Reply