cd

Today's Command is "cd":


What will it do:

This command is used to change the current working directory.

How to use it:

user@box ~$ cd /tmp

The above command will change the current working directory to '/tmp'. If you look at the prompt you will see that we were in the user's home directory, indicated by '~', while issuing the command.

user@box /tmp$ cd ..

The above command will take you to the immediate parent of the current working directory. In this example it would take you to '/'.

user@box /usr/local/share/doc$ cd

This would bring you back to your home directory. Although we were in '/usr/local/share/doc' while issuing the command, it will have the same effect even of you were in some other location.

Interestingly, 'cd' allows you to swap your current and previous working directories through the use of the '-' parameter. The following example would help you to understand how this works.

user@box ~$ cd /tmp
user@box /tmp$ cd -
/home/usr
user@box ~$ cd -
/tmp
user@box /tmp$ cd /usr/local/share/doc
user@box /usr/local/share/doc$ cd -
/tmp
user@box /tmp$

Options

'cd' is a very straightforward command and as such does not have much options. You can still have a look at the manual though.

user@box $~ info cd
user@box $~ man cd