Ugacomp

How to use the cd command to navigate Linux directories

Where necessary, you may need to have access to a VPS server so you can follow how to implement the steps in this article.  You can get a cheaper VPS Server from Contabo with 4vCPU cores, 8GM RAM, and 32TB Bandwidth for less than $5.50 per month. Get this deal here now

Table of Contents

Cloud VPS S

$5.50 Monthly
  • 4 vCPU Cores | 8GB RAM

CLOUD VPS M

$15.50 Monthly
  • 6 vCPU Cores | 16GB RAM

CLOUD VPS L

$17.50 Monthly
  • 8 vCPU Cores | 24GB RAM

Understanding how to navigate through Linux directories using the command terminal is an important skill for a system administrator, developer or cloud engineer.

In this article, we will guide you step-by-step how to use the cd command to browse through Linux directories:

What is the cd command in Linux

The cd command stands for ‘change directory’ and it is a command used to change  the current directory to another.  Let’s say your current directory is folder_A, and to move to a different directory, Folder_B, you would need to use the cd command on the Linux terminal.

The basic syntax for using the cd command to navigate to directories is as follows’;

cd [directory]

Navigating to an Absolute path

An absolute path is any directory path that starts from root with a forward slash. For example:

  • /home/user/documents/file.txt
  • /etc/nginx/nginx.conf

With the cd command, you can move a specific directory by specifying its absolute path:

cd /home/user/Documents

The above command takes you to the Documents directory.

Navigating to Relative Path

A relative path specifies the location of a file or directory in relation to the current working directory. A relative path does not start from the the root directory but starts from the current directory you are in.

For example, the following command takes us to Downloads, which is located in the current working directory:

cd Downloads

Basically, the starting point of the relative path is your current working directory you’re operating in.

RECOMMENDED READING: How to list files and directories using the ls command in Linux

Moving to the Home Directory

A home directory is the default directory allocated to every Linux user. If you want to go back to your home directory from wherever you’re on Linux, there two ways to do it:

  • Typing cd without any arguments:

cd

  • Using the ~ (tilde) symbol:
cd ~

Navigating Up the Directory Tree

You can move up one level in the directory hierarchy using the double dots ..

cd ..

If you need to move up multiple levels, you can repeat .. with slashes. For example, to move up two levels:

cd ../..

Returning to the Previous Directory

To go back to the last or previous directory you in, you can use dash - (dash):

cd -

For example, if you were in /home/user/Documents, moved to /var/log, and then ran cd -, you’d return to /home/user/Documents.

Exploring Hidden Directories

In Linux, directories that start with a dot in their names are hidden. To navigate to such directories, you need to include the dot in the path:

cd ~/.config

Navigating Through Multiple Levels in One Command

You can navigate through multiple directory levels in one command. For instance, if you are in your home directory and want to move to /home/user/Documents/work, you can do so in one step:

cd Documents/work

Dealing with Spaces in Directory Names

If your directory names contain spaces, you need to enclose them in quotes or escape the spaces with a backslash:

cd "My Documents"

or

cd My\ Documents

Hire us to handle what you want

Hire us through our Fiverr Profile and leave all the complicated & technical stuff to us. Here are some of the things we can do for you:

  • Website migration, troubleshooting, and maintenance.
  • Server & application deployment, scaling, troubleshooting, and maintenance
  • Deployment of Kubernetes, Docker, Cloudron, Ant Media, Apache, Nginx,  OpenVPN, cPanel, WHMCS, WordPress, and more
  • Everything you need on AWS, IBM Cloud, GCP, Azure, Oracle Cloud, Alibaba Cloud, Linode, Contabo, DigitalOcean, Ionos, Vultr, GoDaddy, HostGator, Namecheap, DreamHost, and more.
 

We will design, configure, deploy, or troubleshoot anything you want. Starting from $10, we will get your job done in the shortest time possible. Your payment is safe with Fiverr as we will only be paid once your project is completed.