cd
cd
is used to change directory. Unlike most commands, cd
is not
a separate program, it is a shell built-in. cd
is a useful tool to navigate up and down the hierarchy of the file systems on your machine, and move into a given directory.
$ cd ~
$ cd /home
Useful Options / Examples
cd -
Jump to the last directory that you were in. This will not always necessarily be the parent to your current directory, which would instead be the case if you were to use cd ..
(Note that this command prints current path after completion)
Alborz-Brals-MacBook-Pro:basics abral$ pwd
/Users/abral/Desktop/Computer_Science/EECS 398 (C4CS)/adv_HW_7_2/cse80.github.io/_commands/basics
Alborz-Brals-MacBook-Pro:basics abral$ cd /tmp
Alborz-Brals-MacBook-Pro:tmp abral$ pwd
/tmp
Alborz-Brals-MacBook-Pro:tmp abral$ cd -
/Users/abral/Desktop/Computer_Science/EECS 398 (C4CS)/adv_HW_7_2/cse80.github.io/_commands/basics
cd ..
Another way to jump back directory
The two dot characters ..
represent the parent directory to the current directory in which we are working
Alborz-Brals-MacBook-Pro:basics abral$ pwd
/Users/abral/Desktop/Computer_Science/EECS 398 (C4CS)/adv_HW_7/cse80.github.io/_commands/basics
Alborz-Brals-MacBook-Pro:basics abral$ cd ..
Alborz-Brals-MacBook-Pro:_commands abral$ pwd
/Users/abral/Desktop/Computer_Science/EECS 398 (C4CS)/adv_HW_7/cse80.github.io/_commands
cd .
The one dot character .
represents the current directory in which we are working. This command simply moves us to our current directory
Alborz-Brals-MacBook-Pro:basics abral$ pwd
/Users/abral/Desktop/Computer_Science/EECS 398 (C4CS)/adv_HW_7/cse80.github.io/_commands/basics
Alborz-Brals-MacBook-Pro:basics abral$ cd .
Alborz-Brals-MacBook-Pro:basics abral$ pwd
/Users/abral/Desktop/Computer_Science/EECS 398 (C4CS)/adv_HW_7/cse80.github.io/_commands/basics
Of course, this accomplishes nothing; however, there are other uses for the .
character pertaining to the cd
command. Some of the more common uses can be found on the dot(.) page of the C4CS website
cd
Jump back to home directory (same as “cd ~” or “cd /home”)
Alborz-Brals-MacBook-Pro:basics abral$ pwd
/Users/abral/Desktop/Computer_Science/EECS 398 (C4CS)/adv_HW_7/cse80.github.io/_commands/basics
Alborz-Brals-MacBook-Pro:basics abral$ cd
Alborz-Brals-MacBook-Pro:~ abral$ pwd
/Users/abral
cd /
Jump to the root directory
Alborz-Brals-MacBook-Pro:basics abral$ pwd
/Users/abral/Desktop/Computer_Science/EECS 398 (C4CS)/adv_HW_7/cse80.github.io/_commands/basics
Alborz-Brals-MacBook-Pro:basics abral$ cd /
Alborz-Brals-MacBook-Pro:/ abral$ pwd
/