What is cd in Linux?

The cd command in Linux stands for change directory. It is used to change the current directory of the terminal. The terminal, by default, opens the home directory.

The cd command comes as part of the GNU Core Utilities, available on all Unix-like operating systems.

For this shot, we will use the ls command to list all folders within the current directory.

Arguments

The cd command accepts several types of arguments. We will go through the most frequently used ones in this shot.

cd /

To go to the root directory, we input / as the argument.

cd

We do not provide any arguments to the cd command to go to the home directory.

cd . .

To shift one level above the current directory, we input .. as the argument.

cd -

To go to the previous directory, we use - as our argument.

cd /folder/subfolder

For custom navigation across any directory, we can send its path as the argument.

Example

The following example demonstrates how to use the cd commands and their different arguments in terminal.

First, we use the ls command to list all the folders in the home directory. Subsequently, we use the cd command to go to the bin folder and list all the folders in bin.

We shift one level above using the cd .. command and are back in the home directory as confirmed using the ls command. Using cd with no arguments, we go to the root folder.

Terminal 1
Terminal
Loading...

Free Resources

Copyright ©2024 Educative, Inc. All rights reserved