Skip to main content

Everything about cd command in UNIX

Sanjeev Kumar Jaiswal's picture

analysis of cd command.Hi Alien Coders....its not an alien thing to write about cd. Yeah cd(change directory) not CD(Compact Disc) :P . Either you are working on Windows or Unix flavors O.S, the most easiest and usual command is cd, correct?

cd means change directory (as everyone knows) and its more powerful in Unix rather than Windows i guess. Window is having only cd path_of_the_diretory or cd .. but in Unix or specifically in Linux cd command is having lots of options. Lets explore one by one:

1. cd path_of_directory This command is used to enter into the directory whichever is specified either absolute or relative Ex: # cd /home/jaiswal/songs/audio/bollywood (absolute path) # cd  songs/audio/bollywood   (relative path when u r already at /home/jaiswal)

2. cd .. This command is used to move one step up form the current directory. If you are at /home/jaiswal/songs/audio/bollywood (keep it as a base of the examples) and want to move one directory up use cd .. Ex: # cd ..  (now current directory will be /home/jaiswal/songs/audio) # cd ../../../movies  (moved up three directories and entered into movies directory now i.e. /home/jaiswal/movies)

3. cd - This command comes very handy when you are working with files and one is at other directory and one is at another directory. For example: suppose one file is at /opt/bin/perl/codes and other is at /opt/bin/perl/modules/jaiswal/modules Now go to one directory using cd. Like cd /opt/bin/perl/codes then again type cd /opt/bin/perl/modules/jaiswal/modules and now use cd - You will be returned back to previous one which you used with cd. now use cd - as many time as you wish to switch over those two directories.

Ex:

  1. # cd /opt/bin/perl/codes
  2. # cd /opt/bin/perl/modules/jaiswal/modules
  3. # cd - /opt/bin/perl/codes
  4. # cd - /opt/bin/perl/modules/jaiswal/modules
  5.  
Yes , you are right cd - is doing two work at a time.

1. Bringing back to previous used cd directory path and 2. also print the current directory path just like pwd

4. cd -- or cd ~ or cd Yes all three commands will let you drive to user's home directory most probably /home/user_name like /home/jaiswal ex: #  cd -- or cd ~ or cd (don't write all three commands all together just i wrote. use any one if at one time buddy.) Windows have no such option as far as i have tried (if it is there let me know ) # pwd /home/jaiswal # I hope you will like it although even you know all these commands, you will find rarely any article on this which will explain like this. What say?

SpallFege (not verified)
Just want to say what a great
Just want to say what a great blog you got here! I've been around for quite a lot of time, but finally decided to show my appreciation of your work! Thumbs up, and keep it going! Cheers Christian.
sanjeev (not verified)
Thanks a lot. Will keep our
Thanks a lot. Will keep our motivations and motto high to reach to the rest of the tech world
SpallFege (not verified)
Just want to say what a great
Just want to say what a great blog you got here! I've been around for quite a lot of time, but finally decided to show my appreciation of your work! Thumbs up, and keep it going! Cheers Christian
nawalmishra (not verified)
thanx sir.... it will really
thanx sir.... it will really useful as nos lab going on
PuZZleDucK (not verified)
Nice
Hey, nice work... and the "cd -" move is sweet, didn't know about that one.
sanjeev's picture
Offline
Joined: 21 Feb 2011
cd - is really very handy and useful
cd - is really very handy and useful
Thanks for liking our artciles and pondering your thoughts :D

Follow us at :
Facebook | Twitter
########### Give me the right place to stand, I shall move the earth. #################

Post new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.