To change the shell working directory, we use the cd command in the Linux system.
The cd command used to change the current working directory in the Linux/Unix operating system. In the Windows operating system for the same purpose the cd or chdir command available. The cd command also available in the EFI shell (Extensible Firmware Shell). By default, the current shell working directory is home directory.
The general syntax of the cd command is as follows −
cd [-L| [-P [-e]] [-@]] [directory]
A brief description of options available in the cd command.
|Sr.No.||Option & Description|
Force soft links to as followed
Resolve symbolic links in the directory after processing instances of ‘..’
Use physical directory structure without soft links
If the -P option is used, and the current shell working directory cannot be determined successfully, exit with a non-zero status
On systems that support it, present a file with extended attributes as a directory containing the file attributes
Display this help and exit
By default, the shell working directory is the home directory. To change working directory home to another directory, we use the cd command as shown below
$ cd shadow
Here, we changed the shell working directory to a specified shadow directory.
To change the shell working directory current working directory to home directory, we use the cd command with the ‘~’ sign as shown below.
$ cd ~
To check-in which directory currently we are, we use the pwd (print working directory) command as shown below.
If we are currently in-home directory then the output of the pwd command is as follows:
To change the current directory to inside a directory from a directory, we use the cd command as shown below.
$ cd shadow/snow
Here, we have a directory shadow and snow is a directory inside the shadow directory. To navigate snow directory, we use shadow/snow with the cd command.
To change the current working directory to the parent directory, we use ‘..’ with the cd command as shown below.
$ cd ..
To check more information about the cd command, we use the cd command with --help option as shown below.
$ cd --help