02. cd commands - muneeb-mbytes/linux_course GitHub Wiki

cd command:

"cd" command in Linux known as change directory command. It is used to change current working directory.

cd dia

     Fig-1: These are all the variations that you have in "cd" command.

Cheat Sheet for all variations of "cd" commands:

Sr.no cd commands with different variations description
1 cd directory_name Get into the particular directory.
2 cd .. Go back to previous directory.
3 cd dir_1/dir_2 Get into the directory which is inside other directory using path.
4 cd ~ Directly goes to the home directory.
5 cd / Directly goes to the root directory.
6 cd - Jump back to the previous state (i.e, where you came from).
7 cd -p directory_name Get into the directory and Displays the path of the directory where you go.
8 cd directory\ name Get into the directory which has a space in its name.
9 cd --help Gives all the possible variations available in cd.

Different Variations of CD Command:

cd directory_name

This command is used to get into a directory from your current directory only if the directory already created.

In the below Fig-2 you can see that by using cd fruits command you will enter into the fruits directory from cd_commands directory.
Also, you can see in below Fig-2 it has 2 paths displayed in it they are:
Path-1: I have used pwd in source file to check the path where you are currently in.
Path-2: I have used pwd in source file to check the path after using cd directory_name command.

cd -dir (2)

      Fig-2: Usage of cd Directory_name command.

The below GIF shows the whole process from sourcing scripting file till the output.

cd_gif

      GIF-1: giphy for cd directory_name command.

GitHub Link: https://github.com/muneeb-mbytes/linux_course/blob/b7_Team_BJT/cd_commands/cd.csh

cd ..

This command is used to move to previous directory by one step from current directory.

In the below Fig-3 you can see that by using cd .. command you will enter into the apple directory from banana directory.
Also, you can see in below Fig-3 it has 2 paths displayed in it they are:
Path-1: I have used pwd in source file to check the path where you are currently in.
Path-2: I have used pwd in source file to check the path after using cd .. command.

cd-go-back (1)

      Fig-3: Usage of cd .. command

The below GIF shows the whole process from sourcing scripting file till the output.

cd_go_back_gif

      GIF-2: giphy for cd .. command

GitHub Link: https://github.com/muneeb-mbytes/linux_course/blob/b7_Team_BJT/cd_commands/cd_go_back.csh

cd dir_1/dir_2/dir_3

This command is for going into multiple sub directories which are from current directory.

In the below Fig-4 you can see that by using cd dir_1/dir_2/dir_3 command you will enter into the banana directory from cd_commands directory.
Also, you can see in below Fig-4 it has 2 paths displayed in it they are:
Path-1: I have used pwd in source file to check the path where you are currently in.
Path-2: I have used pwd in source file to check the path after using cd dir_1/dir_2/dir_3 command.

cd-sub (1)

     Fig-4: Usage of cd dir_1/dir_2/dir_3 command.

The below GIF shows the whole process from sourcing scripting file till the output.

cd_sub_gif

      GIF-3: giphy for cd dir_1/dir_2/dir_3 command.

GitHub Link: https://github.com/muneeb-mbytes/linux_course/blob/b7_Team_BJT/cd_commands/cd_sub_dir.csh

cd ~

This command is used to change directory to the home directory from current directory.

In the below Fig-5 you can see that by using cd ~ command you will enter into the home directory (i.e,/home/johnshahid this home path is for me) from banana directory.
Also, you can see in below Fig-5 it has 2 paths displayed in it they are:
Path-1: I have used pwd in source file to check the path where you are currently in.
Path-2: I have used pwd in source file to check the path after using **cd ~** command.

cd_home

      Fig-5: Usage of cd ~ command.

The below GIF shows the whole process from sourcing scripting file till the output.

cd_home_gif

      GIF-4: giphy for cd ~ command.

GitHub Link: https://github.com/muneeb-mbytes/linux_course/blob/b7_Team_BJT/cd_commands/cd_home.csh

cd /

This command is used to change directory to the Root Directory from current directory.

In the below Fig-6 you can see that by using cd / command you will enter into the root directory (i.e,/) from banana directory.
Also, you can see in below Fig-6 it has 2 paths displayed in it they are:
Path-1: I have used pwd in source file to check the path where you are currently in.
Path-2: I have used pwd in source file to check the path after using cd / command.

cd-root (1)

      Fig-6: Usage of cd / command.

The below GIF shows the whole process from sourcing scripting file till the output.

cd_root_gif

      GIF-5: giphy for cd / command.

GitHub Link: https://github.com/muneeb-mbytes/linux_course/blob/b7_Team_BJT/cd_commands/cd_root.csh

cd -

This command is used for go back to previous state where you came from.

In the below Fig-7 you can see that by using cd - command you will enter into the cd_commands directory from banana directory.
Also, you can see in below Fig-7 it has 3 paths displayed in it they are:
Path-1: I have used pwd in source file to check the path where you are currently in.
Path-2: I have used pwd in source file after entering into sub directories by using cd dir_1/dir_2 command.
Path-3: I have used pwd in source file to check the path after using cd - command.

cd -jump_previous (1)

      Fig-7: Usage of cd - command.

The below GIF shows the whole process from sourcing scripting file till the output.

cd_jump_previous_gif

      GIF-6: giphy for cd - command.

GitHub Link: https://github.com/muneeb-mbytes/linux_course/blob/b7_Team_BJT/cd_commands/cd_jump_previous.csh

cd -p directory_name

This command is used to change directory to specified directory from current directory and also provides the path starting from root directory till the directory where you are currently in.

In the below Fig-8 you can see that by using cd -p banana command you will enter into the banana directory from apple directory and it will also show you the path without using pwd command. Also, you can see in below Fig-8 it has 2 paths displayed in it they are:
Path-1: I have used pwd in source file to check the path where you are currently in.
Path-2: After using cd -p directory_name command it has worked as pwd.

cd-path (2)

      Fig-8: Usage cd -p directory_name command.

The below GIF shows the whole process from sourcing scripting file till the output.

cd_path_gif

      GIF-7: giphy for cd -p directory_name command.

GitHub Link: https://github.com/muneeb-mbytes/linux_course/blob/b7_Team_BJT/cd_commands/cd_path_and_enter.csh

cd Directory\ name

This command is used to change directory which directory name has space in it.

In the below Fig-9 you can see that by using cd banana\ tree command you will enter into the banana tree directory from apple directory.
Also, you can see in below Fig-9 it has 2 paths displayed in it they are:
Path-1: I have used pwd in source file to check the path where you are currently in.
Path-2: I have used pwd in source file to check the path after entering into directories by using cd banana\ tree command.

cd-dir-space (1)

      Fig-9: Usage of cd directory\ name command.

The below GIF shows the whole process from sourcing scripting file till the output.

cd_dir_space_gif

      GIF-8: giphy for cd directory\ name command.

GitHub Link: https://github.com/muneeb-mbytes/linux_course/blob/b7_Team_BJT/cd_commands/cd_dir_space.csh

cd --help

This command is used to display all possible options of cd command.

In the below Fig-10 you can see that [-plvn] are different options in cd which can be used individually.

cd -help (1)

      Fig-10: cd --help

Errors and Solutions

Error-1:

syntax error because command must have space.

newerror (1)

Solution:

Refer cd Command - cd directory_name

cd-error-solution (1)


To learn ls command : https://github.com/muneeb-mbytes/linux_course/wiki/03.-ls-commands