Tuesday, February 05, 2008

Linux : cd: Changes to another working directory

cd [options] [directory]


The cd builtin makes directory the working directory.

Arguments

The directory is the pathname of the directory you want to be the new working directory. Without an argument, cd makes your home directory the working directory. Using a hyphen in place of directory changes to the previous working directory.

Notes

The cd command is a bash and tcsh builtin.


Without an argument, cd makes your home directory the working directory; it uses the value of the HOME (bash;) or home (tcsh) variable for this purpose.

With an argument of a hyphen, cd makes the previous working directory the working directory. It uses the value of the OLDPWD (bash) or owd (tcsh) variable for this purpose.

The CDPATH (bash;) or cdpath (tcsh; ) variable contains a colon-separated list of directories that cd searches. Within the list a null directory name (::) or a period (:.:) represents the working directory. If CDPATH or cdpath is not set, cd searches only the working directory for directory. If this variable is set and directory is not an absolute pathname (does not begin with a slash), cd searches the directories in the list; if the search fails, cd searches the working directory.

Examples

The following cd command makes Alex's home directory his working directory. The pwd builtin verifies the change:

$ pwd

/home/alex/literature

$ cd

$ pwd

/home/alex


The next command makes the /home/alex/literature directory the working directory:

$ cd /home/alex/literature

$ pwd

/home/alex/literature


Next the cd utility makes a subdirectory of the working directory the new working directory:

$ cd memos

$ pwd

/home/alex/literature/memos


Finally cd uses the . . reference to the parent of the working directory to make the parent the new working directory:

$ cd ..

$ pwd

/home/alex/literature

No comments: