Linux provides a parent-to-child directory architecture. For a new user, it is important to understand this architecture, on the other hand, it can be frustrating for a new user to navigate through the directories. Ubuntu 22.04 also uses this architecture, for navigating the directories.
In this article, we will explain how a newbie can navigate through the directories using the Ubuntu 22.04 terminal.
How do you go back to a directory in the bash of Ubuntu 22.04?
It is important for a new user of Ubuntu, to understand the storage architecture of the operating system. All the Linux-based operating systems follow the same parent-to-child directory architecture. You can go to a specific directory by following a series of steps. You can not go to a specific directory, by only typing the name in the terminal. Follow these steps to navigate back through the directories:
Basic Understanding Directories
If you are a beginner, then you must know about some basic commands used for directories. In this section, we will explain some of these commands:
$ pwd Command
If you are in a particular directory and the location is unknown to you. You can use the “pwd” command to print the name of the directory. The command syntax is as follows:
$ pwd
The command will display the directory name.
$ ls Command
If you want to see a particular file or a folder in a directory you can list down the directories by using the “ls” command. It is very helpful for searching out a specific directory. The syntax of the command is as follows:
$ ls
The command will list down all the sub-directories present in the location.
$ cd Command
The “cd command” is used to change the directories. You can use this command to navigate through the directories. In this section we will explain all the possible ways to use the cd command. The syntax of the command is as follows:
$ cd "<name of directory>"
The command will change the directory to the specified location.
Now you can follow along to learn all the possible ways to go back to a directory.
Method 1: Using the “cd ..”
If you want to go back to a directory in the Ubuntu 22.04 terminal, you can use the “cd ..” command. It will move to the parent directory. The syntax of the command is as follows:
$ cd ..
The command moves to the parent directory as shown below:
You can use the “pwd” command to print the working directory.
Method 2: Using “cd ../..”
Sometimes, it is possible that you are in the sub-directory of the parent directory, and you want to go to the parent directory. Then you can use the “cd ../..” command, the command moves you to two levels up.
The syntax of the command is as follows:
$ cd ../..
For instance, you are in the sub-directory of the home directory, and you want to move back to the home directory by using the “cd ../..” command. The execution of command is shown below in diagram:
Similarly, if you want to move three levels up you can use the following command:
$ cd ../../..
The command will move three levels up as shown in the diagram:
Method 3: Moving to the Home Directory
Mostly a user wants to move to the home directory immediately. Then you can use the following commands:
- $ cd
- $ cd ~
- $ cd $HOME
Type the “cd” command in the terminal and you’ll be returned to the home directory:
Next type and see the output of cd ~ command:
You can specify cd $HOME variable for going to the home directory, the output is as follows:
Method 4: Moving to the Previous Directory using cd –
You can move to the previous directory by using the “cd –” command. By using this command you can move to the previous current directory. The syntax of the command is shown below:
$ cd -
The output of the command is shown below. My current directory was home. But my previous directory was the “Myfiles” directory. As I type the command ”cd –”, it returns me to the previous directory:
This is how you can move back and navigate through the directories by using different commands.
Conclusion
To move back a directory in the Ubuntu 22.04 terminal, you can use different commands like “cd -, cd .., cd ../.. and cd ../../..”. You can also go to the home directory by using cd, cd ~, and cd $HOME. In this article, we have explained how you can go back to a directory in the terminal of Ubuntu 22.04.