cd: cd [-L] [-P [-e]] [dir]
Change the current directory to DIR.The default DIR is the value of the HOME shell variable.
The variable CDPATH defines the search path for the directory containing DIR.Alternative directory names in CDPATH are separated by a colon(:).A null directory name is the same as the current directory. If DIR begins with a slash(/), then CDPATH is not used.
If the directory is not found,and the shell option `cdable_vars` is set,the word is assumed to be a variable name.If that variable has a value,its value is used for DIR.
Options:
-L force symbolic links to be followed
-P use the physical directory structure without following symbolic links
-e if the -P option is supplied,and the current working directory cannot be determined successfully,exit with a non-zero status
The default is to follow symbolic links,as if '-L' were specified.
Exit Status:
Return 0 if the directory is changed,and if $PWD is set successfully when -P is used;non-zero otherwise.
Since cd is used to change the current directory to DIR,what is DIR?
DIR is a pathname,which can be determined by command line argument [dir].
If [dir] is empty,DIR is the value of the HOME shell variable.
huihoo@huihoo:/home/huihoo/lab$ HOME=/tmphuihoo@huihoo:/home/huihoo/lab$ echo $HOME/tmphuihoo@huihoo:/home/huihoo/lab$ cdhuihoo@huihoo:~$ pwd/tmphuihoo@huihoo:~$If [dir] is null,namely "", DIR is the same as the current directory.
huihoo@huihoo:~/lab$ pwd/home/huihoo/labhuihoo@huihoo:~/lab$ cd ""huihoo@huihoo:~/lab$ pwd/home/huihoo/labhuihoo@huihoo:~/lab$If [dir] begins with a slash(/), then DIR is the same as [dir].
huihoo@huihoo:~/lab$ cd /tmphuihoo@huihoo:/tmp$ pwd/tmphuihoo@huihoo:/tmp$If [dir] is a relative pathname,then she SHELL variable CDPATH works.It defines the search path for the directory containing DIR.Alternative directory names in CDPATH are separated by a colon(:).
If CDPATH is null,relative pathname is relative to current directory.
huihoo@huihoo:~$ echo $CDPATH/libhuihoo@huihoo:~$ ls /lib/firmware/b43 -d/lib/firmware/b43huihoo@huihoo:~$ cd firmware/b43/lib/firmware/b43huihoo@huihoo:/lib/firmware/b43$ pwd/lib/firmware/b43huihoo@huihoo:/lib/firmware/b43$
If the [dir] directory is not found(including CDPATH and current directory),and the shell option 'cdable_vars' is set,[dir] is assumed to be a variable name,
huihoo@huihoo:/tmp$ CDPATH=/libhuihoo@huihoo:/tmp$ firmware=/tmphuihoo@huihoo:/tmp$ cd firmware/lib/firmwarehuihoo@huihoo:/lib/firmware$ doc=/tmphuihoo@huihoo:/lib/firmware$ ls /lib/docls: cannot access /lib/doc: No such file or directoryhuihoo@huihoo:/lib/firmware$ cd doc/tmphuihoo@huihoo:/tmp$ shopt cdable_varscdable_vars on huihoo@huihoo:/tmp$