Use “cd” to change the working directory.
Go to Specific Directory
If we want to go to “/home” directory then we can use-
cd /home
Go to Root Directory
Move to the root directory which is denoted by “/”-
# Go to root directory of the file system
$ cd /
$ pwd
/
BashGo to Home Directory
If you want to go to the home directory of the current user, then use the tilde sign(~) to denote the current user’s home-
$ cd ~
$ pwd
/home/bigboxcode
BashOr just using “cd” will take you to the home directory-
$ cd
$ pwd
/home/bigboxcode
BashGo to Previous Location
Use a dash (-) to go to the previously accessed location-
# Go to /home directory
$ cd /home
# Go to /var/log
$ cd /var/log
# Go to previous directory
# which is /home
$ cd -
/home
# Go to previous directory
# which is /var/log
$ cd -
/var/log
# Go to previous directory again
# which is /home
$ cd -
/home
# Go to previous directory again
# which is /var/log
$ cd -
/var/log
BashGo Relative to Current Directory
If we want to refer to some directory relative to the current directory, then we can use dot(.) to denote the current directory.
Like, if we want to go to the “test” directory which is in the current working directory then we can do the following
$ cd ./test
# or
$ cd test
BashGo to Absolute Path
Use the absolute path from the root directory to go to some specific location-
$ cd /home/bigboxcode/www
$ cd /var/log
$ cd /etc/nginx
BashGo to Parent Directory
If we want to go back to the parent directory then we can use two dots(..) to denote the parent directory, like below-
$ cd ..
BashGo to Multiple Steps back
Say we want to go to some directory which are 2 directories(parent) back and then the name of the directory is “my_project”, then we can use-
# Go to directory which is 2 step back and name is "my_Project"
$ cd ../../my_project
Bash