Name

cd

Synopsis

cd [-LP] [dir]
cd [-LP] [-]

With no arguments, change to home directory of user. Otherwise, change working directory to dir. Bash searches the CDPATH variable first, and then looks in the current directory for dir. A directory of - stands for the previous directory.

Options

-L

Use the logical path (what the user typed, including any symbolic links) for cd .. and the value of PWD. This is the default.

-P

Use the actual filesystem physical path for cd .. and the value of PWD.

Example

$ ls -ld /usr/tmp		/usr/tmp is a symbolic link
lrwxrwxrwx  1 root root 10 Dec 30  2004 /usr/tmp -> ../var/tmp 
$ cd -L /usr/tmp		Logical change directory
$ pwd				Show location
/usr/tmp				Result is logical location
$ cd -P /usr/tmp		Physical change directory
$ pwd				Show location
/var/tmp				Result is physical location

Get bash Quick Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.