cd Command in Linux

In this tutorial, you’ll explore how to use the cd command in Linux. The cd (“change directory”) command is used to change the current working directory in Linux and other Unix-like operating systems. It is one of the most basic and frequently used commands when working on the Linux terminal.

The current working directory is the directory (folder) in which the user is currently working. Whenever you interact with your command prompt, you work in a directory.

Options

You can use these options with its main command by using the hyphen (-).

For example:

cd [-L|-P] [directory]

Here cd is the main command and -L or -P is the option.

Note: You can also refer to options as flags.

Syntax:

You have to follow the below syntax to use the ls command.

cd [options] [directory]

or

cd [options][directorya directoryb]

In the command above:

  • cd: Invokes the cd command.
  • [options]: Adding options changes the way the command executes.
  • [directory]: Path to the directory you want to move into.

cd Command in Linux

Run the following command to change the current directory in a simple format.

cd Downloads

 

cd command in Ubuntu

The ls command is used to list all of the content of the current working directory

Different functionalities of the cd command :

Navigate to the root Directory

The root directory is the first directory in your filesystem hierarchy.  If we have to go to the root directory then we have to use the following command:

cd /

 

Navigate to the root Directory

Navigate to the Home Directory

To navigate the home directory we have to use the cd command. But here if you want to go directly to your home directly you can use a tilde ( ~ ) character, as you can see below:

cd ~

If you want to go to any directory inside the home directory you can use the following command

cd ~/Downloads

Navigate to the Home Directory

Navigate to the Previous Directory

To change back to the previous working directory, pass the dash (-) character as an argument to the cd command:

Navigate to the Previous Directory

Conclusion

We show you how to use the cd command in Linux. Now you can use the Linux cd command to navigate and change the current working directory in the terminal window, see the man page for the cat command.

If you have any questions please leave them in the comments below

Leave a Reply

Your email address will not be published. Required fields are marked *