How To Change Directory In Linux?

Linux provides different ways and commands in order to change the current working directory. Changing directory is especially important while working on the command line or terminal but also used with GUI applications. In this tutorial, we will talk about “How To Change Directory In Linux?”. Instructions described in this tutorial can be used for most of the popular Linux distributions like Ubuntu, Debian, Mint, Kali, CentOS, SUSE, Gentoo, Fedora, RHEL, etc.

Linux Directory Hierarchy

Linux and Unix operating systems and distributions has very simple directory hierarchy where there is / (root) directory where all other files, directories, partitions are connected under this. Under the root directory directories like bin , boot , dev , home etc. exist.

Linux Directory Hierarchy

List Current Working Directory with pwd Command

pwd command is used in order to print current working directory. Current working directory is the directory where the terminal currently running. In some cases listing or displaying current working directory will be usefull before changing directory.

$ pwd

When we first login into the Linux or open a terminal the default directory will be the home of the current user.

Before changing directories, we may need to list the current working path or other path directories. The ls command can be used to list files and directories. We can list using the -l option below.

List Directories

$ ls -l
List Directories

Change Directory with cd Command

The most popular command to change directory is cd command. cd is the short form of the change directory. cd command is also available for different operating systems and platforms like Windows, MacOSX etc. It has very simple syntax where the directory we want to change is provided as parameter to the cd command.

  • PATH is absolute, relative path or parent, child directory.

We will start with a simple example where we will provide the directory name in the current working path. In the following example, we will navigate to the directory named Downloads in the current working path.

$ cd Downloads

Also we can navigate into multi level directories in a single cd command like below. We will navigate to the ismail , Downloads , test directory like below.

$ cd ismail/Downloads/test

Change To Parent Directory

cd command can be used with the special sign like .. which means the parent directory of the current working directory. It will simply express one level upper or parent directory. Let’s make an example. Print the current working directory with the pwd command.

$ pwd

The current working directory is /home/ismail/Downloads . We will navigate to the /home/ismail with the following command.

$ cd ..

We can also use the upper directory multiple times to move multiple level upper directory.

$ cd ../../

Change with Absolute Path

There are two type of paths: Relative Path is set according to the current directory and Absolute Path is set according to the full or complete path. We can use absolute path in order to change directory.

$ cd /home/ismail/Downloads

$ cd /etc/network

$ cd /var/lib

$ cd /var/

Change To Home Directory

Home is the current user personal directory used to store files, folders, etc. A user can navigate to change to his home directory in the following different ways. Simple running the cd command will change to the current user home directory. Also, the ~ tilda sign specifies the current user home directory.

$ cd 

$ cd ~

$ cd ~/Downloads

Change To Root Directory

Root is the highest level of directory in a Linux file system. All other files, folders and partitions are stored and mounted under the root directory. You can change to the root directory with the following command.

$ cd /

Leave a Comment