How to use cd command featured image

How to use cd command?

The “Change Directory” (cd) command in Linux modifies the user’s current working directory. The command helps to move around in the file system’s directories. The use of this command is really crucial to learn.

example syntax

cd [directory]

Where directory denotes the location of the desired directory by its path. The command will send you to the user’s home directory if you don’t provide a directory.

Flags/options available with cd command

  • “-“  : use this option to go to the previous working directory.
use of cd command with - flag
Note: In the example we changed directory to “kaalvairav” from “home”. When we use “cd -“ we go back to the previous working directory.
  • “~” : Use this option to access the user’s home directory. 
use of cd with ~ flag
Note: As seen in the example we are in the root directory “/” but when we “cd ~”, the directory is instantly changed to the user home directory “/home/kaalvairav” .
  • “..” : With this option with cd changes the current working directory to the parent directory.
use of cd with .. flag
Note: Above example shows “/home/kaalvairav” as working directory. With “cd ..” the directory is changed to “/home” which is the parent directory for “kaalvairav” .
use of cd command with "../../" flag
Note: In addition to simple “cd ..” we can also use “cd ../../” where “..” goes back one directory and “/” is used to combine another “..”. So in the example above “../../” means go back two directories.

Special Note: As shown in the examples “pwd” command have been used to know more about the command
Use of pwd Command

One of the most often used commands in Linux is the cd command, which enables users to enter various directories, travel across the file system, and carry out various activities. The command comes in handy when you need to access a particular file or directory or when you need to change directories in order to run other commands.

It’s important to note that the cd command lacks flags; the parameters I previously described are instead shortcuts for navigating between folders.

In addition to the previously listed choices, you can also access a directory by using its complete path by using the cd. As an illustration, to access the directory /home/user/documents, you can use the command:

cd /home/user/documents

Leave a Comment

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

Scroll to Top
Scroll to Top