Categories: TutorialsUbuntu

How to Use cd Command in Linux

The “cd” command is commonly used to change the current working directory in Linux and other Unix-like operating systems. Change directory is denoted by the letter “cd.” It’s one of the most significant and widely used commands in the Linux system, and you’ll see it a lot. We can move around our system’s folders with the help of this command. We can move back to the previous directory, forward to the next directory, or wherever else. In this article, various cd operations will be applied in order to change directories in Linux.

Different ways to change directories

We will execute the following cd operations on directories:

  • Change to a new directory from the existing one
  • Change the directory using an absolute path
  • Change the directory using the relative path,
  • Go to your home directory
  • Return to your previous directory
  • Switch to the Parent Directory
  • Go to the root directory

Operation 1: Change to a New Directory from the Existing One

We can change our working directory from the current one to a different one. Execute the following command to see the current working directory:

$ pwd

Execute the following command to modify our current working directory:

$ cd < current dir> 

The above output shows the change in directory from home to Desktop. We used the pwd command to display the current working directory, which is “/home/linux,” as shown in the preceding result. Then we used the ‘cd’ command to change our current directory, specifying the new directory’s path as “/home/linux/Desktop”.

Operation 2: Change the Directory Using an Absolute Path,

When utilizing an absolute path to change a directory, we must specify the entire path beginning at the root. Execute the following command to modify our current working directory:

$ cd < specified complete dir> 

We’re updating our directory from ‘home’ to ‘Downloads’ based on the given output. So, starting from the root (/), we’ve provided the entire path “/home/linux/Downloads.” This is known as the absolute path.

Operation 3: Change the Directory Using the Relative Path,

A relative path is a location that is relative to the current directory. Execute the following command to modify our current working directory:

$ cd < specified dir> 

We’re using a relative path to change the directory in the above output. We’ve updated our directory from ‘home’ to ‘Downloads,’ as in the previous example, but we haven’t provided the entire path. This is known as the relative path.

Operation 4: Go to Your Home Directory

Execute the following command to go back to your home directory:

$ cd ~

As you can see from the output above, we were in the Downloads directory before using the “cd” command but by using it now we are in our home directory.

Operation 5: Return to your previous directory

Execute the following command to shift to the previous directory from the current working directory:

$ cd -

We were in the “/Desktop” directory, as evidenced by the preceding output. This working directory has been changed to its previous directory “home/linux” by using this command.

Operation 6: Switch to the Parent Directory

Execute the following command to shift to the parent directory from the current working directory:

$ cd ..

We were in the “/Downloads” directory, as evidenced by the preceding output. As the parent for this directory is “home” so this working directory has been changed to its parent directory “home/linux” by using this command.

Operation 7: Go to the Root Directory

Execute the following command to shift to the root directory from the current working directory:

$ cd /

We were in the “/Templates” directory, as evidenced by the preceding output. As the root for this directory is “home” so this working directory has been changed to its root directory “home/linux” by using this command.

Conclusion

In this article, the basic use of cd command in order to change the directories using different methods is being provided. After reading this article, you will be able to know about the current working directory and you will also have the idea about the use of cd command in order to navigate your system’s directory structure.

Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications including CCNA RS, SCP, and ACE. As an IT engineer and technical author, he writes for various websites.

Ubuntu Server Admin

Recent Posts

Canonical announces 12 year Kubernetes LTS

Canonical’s Kubernetes LTS (Long Term Support) will support FedRAMP compliance and receive at least 12…

24 hours ago

Ubuntu Weekly Newsletter Issue 878

Welcome to the Ubuntu Weekly Newsletter, Issue 878 for the week of February 2 –…

2 days ago

How your feedback shapes the way we support open source software

At Canonical, we firmly believe that delivering an outstanding, customer-centric support experience is impossible without…

2 days ago

How To Install osTicket v1.14 On Ubuntu 20.04

I want to share how to install osTicket v1.14 for Ubuntu 20.04 server. osTicket written…

3 days ago

How To Install WordPress On Ubuntu 20.04

Now I want to share how to install WordPress on ubuntu 20.04 server. WordPress is…

3 days ago

How To Install DNS Server (Bind9) On Ubuntu 20.04

Now I want to share the DNS server installation process on your Ubuntu 20.04 server.…

3 days ago