The cd command in Linux is used to change the current directory. cd is a shell builtin command.
where path specifies the path of the new directory.
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
When you use cd without giving any directory path then cd shifts to the home directory.
As shown above without using any path the directory is changed to home directory which in my case is /home/baljit.
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
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.
An alternate method to shift to home directory is the use of cd ~ (the tilde symbol. Remember to use space between cd and ~)
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.
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.
Now, if you want to shift back to the most recent directory (/home/baljit/cse325), use cd –
Q1. What will happen if you use the command
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