How to change directory in terminal on Ubuntu

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
How to change directory in terminal on Ubuntu
How to change directory in terminal on Ubuntu
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Ubuntu Linux
Software cd
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

How to change directory in terminal on Ubuntu



Twitter icon Follow LinuxConfig.org on Twitter for the latest tips and tricks about Linux!

Changing directories on Ubuntu Linux terminal
Changing directories on Ubuntu Linux terminal

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.

  1. Running the cd command 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 Downloads directory inside of the user linuxconfig’s home directory.

  2. If our terminal is already in the linuxconfig directory, then we do not need to specify the absolute (full) path in the command. Use the relative path like so:
    $ cd Downloads
    
    NOTE
    Use the pwd (present working directory) command to see what directory your terminal is currently in.
  3. 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 /
    
  4. 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 ../..
    
  5. The 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 cd all by itself.

    $ cd
    
  6. To go back to the previous directory where you last were, you can use the - character.
    $ cd -
    



Closing Thoughts

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.