Command to change directory in Linux

Share this post to your friends !

This entry is part 1 of 2 in the series Linux commands: Part 2 - Navigation

WriteBash - To work on Linux systems, you have to work with directories and files, in this article I will talk about changing the working directory in Linux using the cd command.

Like Windows, a Unix-like operating system such as Linux organizes its files in what is called a hierarchical directory structure. This means that they are organized in a tree-like pattern of directories (sometimes called folders in other systems), which may contain files and other directories. The first directory in the file system is called the root directory. The root directory contains files and subdirectories, which contain more files and subdirectories and so on and so on.

The current working directory in Linux

As with the Windows operating system, when you work, you need to know that you are currently in the directory in the system. But on Linux (I mean the command line interface when using Linux on the server) there is no graphical interface to let you know that. So how do you know which directory you are in?

To display information about the current directory, use the following command:

command-to-change-directory-in-linux-01 Command to change directory in Linux
Display current directory with pwd command

Use “cd” command to change directory in Linux

To change your working directory (where we are standing in our tree-shaped maze) we use the cd command. To do this, type cd followed by the pathname of the desired working directory. A pathname is the route we take along the branches of the tree to get to the directory we want. Pathnames can be specified in one of two different ways; as absolute pathnames or as relative pathnames. Let’s deal with absolute pathnames first.

command-to-change-directory-in-linux-02 Command to change directory in Linux
Use cd command to change directory

An absolute pathname begins with the root directory and follows the tree branch by branch until the path to the desired directory or file is completed.

cd /etc/sysconfig

For example, in the image above, we will move to the /etc/sysconfig directory. What this means is, we start with the root directory (represented by the leading slash in the pathname) there is a directory called etc which contains a directory called sysconfig. You can read more about the ls command in the image above.

Changes from subdirectory to parent directory

We have two methods to do this.

The first method uses a relative pathname. This is the most common method because it “type less”. We use command below:

cd ..
command-to-change-directory-in-linux-03 Command to change directory in Linux
Move from subdirectory to parent (method 1)

The second method uses absolute pathname.

command-to-change-directory-in-linux-04 Command to change directory in Linux
Move from subdirectory to parent (method 2)

Changes from parent directory to subdirectory

We have three methods to do this. The first method uses the absolute pathname. The second method uses a relative name path. The third method is “use subdirectory name”.

command-to-change-directory-in-linux-05 Command to change directory in Linux
Move from parent to subdirectory

The third method is the second method of removing the ./ at the beginning of the command. This is the most common method in the 3 methods above.


In the article I talked about how to use the cd command to change the directory on Linux, this is one of the more useful commands later when you start programming the bash script.

Continue reading the seriesNext part: Pathnames types in Linux systems »»
If you liked this article, then please subscribe to our YouTube Channel for more video tutorials. You can also find us on Twitter and Facebook.

Share this post to your friends !
If you appreciate what we share in this blog, you can support us by:
  1. Stay connected to: Facebook | Twitter | Google Plus | YouTube
  2. Subscribe email to recieve new posts from us: Sign up now.
  3. Start your own blog with SSD VPS - Free Let's Encrypt SSL ($2.5/month).
  4. Become a Supporter - Make a contribution via PayPal.
  5. Support us by purchasing Ribbon Lite Child theme being using on this website.

We are thankful for your support.

single post bottom banner
«« »»

Got something to say? Join the discussion

Please keep in mind that all comments are subject to our Comment Policy. Your email address will not be published.
This site uses Akismet to reduce spam. Learn how your comment data is processed.