One of the most fundamental things for users of Ubuntu Linux that you will do on the command line is change your current directory. This allows you to navigate around the file system, and view or interact with files from different directories. In this tutorial, you will learn how to change directory in terminal on Ubuntu.
In this tutorial you will learn:
- How to change directory in terminal on Ubuntu
- How to go to root directory and home directory
- How to move up one directory or back to last directory
|Category||Requirements, Conventions or Software Version Used|
|Other||Privileged access to your Linux system as root or via the
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of
$ – requires given linux commands to be executed as a regular non-privileged user
How to change directory in terminal on Ubuntu
The cd (change directory) command is how you will navigate to different directories throughout your Ubuntu system, at least when working in the command line terminal. See the examples below to learn how to use the
cd command to navigate your file system.
- Running the
cdcommand followed by the directory will just change to the specified directory. First, let’s try changing to an absolute path.
$ cd /home/linuxconfig/Downloads
This takes us to the
Downloadsdirectory inside of the user linuxconfig’s home directory.
- If our terminal is already in the
linuxconfigdirectory, then we do not need to specify the absolute (full) path in the command. Use the relative path like so:
$ cd Downloads
pwd(present working directory) command to see what directory your terminal is currently in.
- We can use
cd /to change to the root directory. The root directory is the directory at the top of your filesystem hierarchy and is represented as a slash character
$ cd /
- To go up one directory in the hierarchy, we can use
cd ... This works because the parent directory is represented by two periods
$ cd ..
You can go back multiple directories at once by listing more double dots. This next example would go backwards two directories.
$ cd ../..
cd ~command can be used to change to the current user’s home directory. Changing to the home directory without this command is a lot less efficient, as the entire file path would have to be specified. We will show you an example of how to use its syntax.
$ cd ~
Another way to do the same thing is by just entering
cdall by itself.
- To go back to the previous directory where you last were, you can use the
$ cd -
In this tutorial, we saw how to change directory in terminal on an Ubuntu Linux system. The
cd command is important to memorize to use the Ubuntu terminal as efficiently as possible when navigating the system’s directories. It is especially useful for its
cd .. functionality, as it allows you to swiftly change to one or more directories backwards without having to type out the entire file path.