Moving across different directories can be a frequent operation while working with Linux. You may need to move forward in some directory or even go to the root directory of your system. All the tasks that require you to move across different directories can be handled by using the cd command in Linux. This command is shorthand for “change directory”. In this article, we will discuss various options available to use with the cd command. Also, we share some examples that will help you understand exactly how the cd command works in a Linux terminal .
What is the cd Command?
This command is used to change the current working directory and navigate either forward or backward in the file system. Moving forward means we are going into some directory that is present within the current directory. On the other hand, moving backwards means we are going to the parent directory of the current directory.
Most Popular cd Commands
If you want to navigate into a subdirectory, you can use the following command:
To navigate into the parent directory or to the directory one level up to the current directory, you need to run the following command:
Switching to the root directory
In case you don’t know, the root directory is the first directory in your system hierarchy. To navigate to the root directory from any directory, you need to execute the following cd command:
To navigate into subdirectories of subdirectories
You can go multiple levels down into the file system with a single cd command which is mentioned below:
Go to the home directory of your system
There is a cd command that allows you to navigate directly to the HOME directory of your Linux file system and is as follows:
In this article, we discussed various options that you can use with the cd command. The cd command is primarily used to switch between different directories of your file system. You can move one or more levels up or down in your file system hierarchy by using different cd commands. Also, you can directly navigate to the root or home directory by using the cd command with appropriate options. People are also reading:
- Shell Commands in Linux
- Basic Linux Commands for Beginners
- How to copy directories in Linux?
- How to use GREP Command in Linux?
- Remove files and directories using Linux Command Line
- How to Become a Linux Administrator?
- How to Extend Linux Partitions with Resize2fs?
- Best Linux Distribution to Use in 2022
- How to use vi editor in Linux?
- Linux vs Windows