- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to change the shell working directory in Linux?
To change the shell working directory, we use the cd command in the Linux system.
cd (change directory)
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
- How to know/change current directory in Python shell?
- How to display the current working directory in the Linux system?
- How to change file or directory permission in Linux/Unix?
- How to change the root directory of an Apache server on Linux?
- How to list the directory content in Linux?
- How to set the current working directory in Python?
- How to decorate your Linux Terminal using Shell?
- How to know current working directory in Python?
- Get the Current Working Directory in Java
- Linux – How to find the files existing in one directory but not in the other directory?
- How to create a new directory in Linux using the terminal?
- How to change current directory using Python?
- Java Program to Get Current Working Directory
- How to find the most recent file in a directory on Linux?
- How to change the permission of a directory using Python?