cd

From Initq

Jump to: navigation, search

Change the current working directory to directory specified. If directory not specified then change to user's home directory.
cd - takes you back to the last directory you were at.

 [alibaba@ohnonono ~]$ cd /var/www/html
 [alibaba@ohnonono html]$ cd
 [alibaba@ohnonono ~]$ pwd
 /home/alibaba
 [alibaba@ohnonono ~]$ cd -
 /var/www/html
 [alibaba@ohnonono html]$

single dot directory is your current directory and the double dot directory is one folder below.

 [alibaba@ohnonono html]$ ls -la
 total 16
 drwxr-xr-x 2 root root 4096 Aug  6  2007 .
 drwxr-xr-x 8 root root 4096 Dec  2 03:31 ..

you can go back or forward in one command. you can also go back to your home directory two ways.

 [alibaba@ohnonono html]$ cd ../../../
 [alibaba@ohnonono /]$ pwd
 /
 [alibaba@ohnonono /]$ cd ~
 [alibaba@ohnonono ~]$ pwd
 /home/alibaba
 [alibaba@ohnonono ~]$ cd
 [alibaba@ohnonono ~]$ pwd
 /home/alibaba

Contents

CDPATH

There is a cdpath env that you can set to quickly change to the often used directory quickly.

[root@localhost ~]# cd yum
-bash: cd: yum: No such file or directory
[root@localhost ~]# export CDPATH=/etc
[root@localhost ~]# pwd
/root
[root@localhost ~]# cd yum
/etc/yum

Add this to your ~/.bash_profile to make it permanent.

cd quickly

Put the following in your ~/.bash_profile

alias ..="cd .."
alias ..2="cd ../.."
alias ..2="cd ../.."
alias ..3="cd ../../.."
alias ..4="cd ../../../.."

cd to last directory

[a507394@localhost ~]$ cd /etc
[a507394@localhost etc]$ cd -
/home/a507394
[a507394@localhost ~]$ cd -
/etc

Misspelled directory names

You have it automatically corrected by doing

shopt -s cdspell
Personal tools