Linux Commands

How do I Navigate in Linux Terminal?

The command terminal on Linux is a CLI (Command-Line Interface), where you type the commands that would otherwise take time with the GUI. It is equivalent to the Command Prompt (CMD) provided in Windows. The terminal is the perfect way a user can truly feel that they are communicating with their system. It feels invigorating when you type commands on the terminal, and the computer performs exactly what you instructed it to do. The terminal is also great for people who want to know what exactly is going on deep inside the computer. You can understand the pathways and the steps taken by the computer to perform even the very basic tasks. In the end, it all comes down to preference.

To truly master the terminal, you first need to learn the basic navigation on it. We will guide you through the commands used to navigate the files and directories present on your Linux system. So, let’s get started.

The “pwd” Command

The Print Working Directory (pwd) command is one of the basic and primary commands users need to learn about. When you open the terminal, you are usually present in the home directory. If you execute any commands, you likely end up in a directory different from the one you started at. To know which directory you are currently in, you can use the pwd command.

The pwd command tells you about the directory you have ended up in. Knowing your whereabouts is crucial in a CLI environment. Hence pwd is important. The syntax for the command is simple; you just need to type:

$ pwd

You should get your directory in output.

The “cd” command

As mentioned earlier, you start in the home directory when you open the terminal. To move around the system to access files and folders, you must continuously change directories. For this purpose, we have the “Change Directory” or the “Cd” command. The name of the command explains its purpose. It is used for shifting from one directory to another.

The basic syntax for this command is:

$ cd [directory]

For example, you must type the following if you want to access the “Downloads” folder.

$ cd /home/username/Downloads

Or you could access it with the following.

$ cd Downloads

To go to the home directory, use this command:

$ cd ~

To go to the previous directory, do this:

$ cd

To go upwards in a directory, we use “../” with the command. For example, it works that you are currently in the “home/user/Downloads” directory. To move to “home/user” you need to type this:

$ cd ../

For getting into the home directory, add another “../”

$ cd ../../

These are the basic variety of commands associated with Cd.

The “ls” Command

Now, as you have learned to move from one directory to another, the next step is to view the contents of the directory you are in. The ls command is used to view all the files and folders present in the current directory.

The syntax for ls is as follows.

$ ls

There are different options available with ls. For example, to view all the hidden files in the current directory, we use -a in tandem with ls.

$ ls -a

If you prefer to see the contents of the directory in an extended form.

$ ls -l

“l” over here signifies “long”.

To view files arranged according to time of modification, type the following.

$ ls -lt

The “mkdir” Command

To create new directories, we use the “Make Directory” or the “mkdir” command. The syntax for this command is given below.

$ mkdir directory name

For example, to make a directory named “wire” in your home directory.

$ mkdir wire

Make sure you are in your home folder.

To make an extended directory, use -p with mkdir.

$ mkdir -p /example/wire

The “touch” Command

You have learned how to make a directory. Now it is time to learn how we can make files inside a directory. Step up the “touch” command. The syntax for touch is given below.

$ touch [filename]

For example, just use the following to create a file named “doc1” inside any directory.

$ touch doc1

To create multiple files at once in the same directory, type the following.

$ touch doc 1 doc2

You can also do this by using the absolute address.

$ touch home/username/doc 1 /home/username/doc2

We can use the touch command to create files in any directory if we use their absolute addresses.

The “mv” Command

So far, we have learned how to make directories and files, move within directories, tell which directory we are in, and see the contents of a directory. Now we move on to moving files within directories and to and from a directory. “Move” or “mv” is used for this purpose, and the syntax for this command is given below.

$ mv file name directory

For example, we type the following to move a file named “ball” to a directory named “wire”.

$ mv ball wire

If you want to move the file “ball” to your home directory, use the “.” operator at the end.

$ mv wire/ball .

Make sure you are in the home directory before you try and execute this command.

The “cp” Command

To copy files and directories into others, we use the “cp” command. “cp” stands for “Copy” and its syntax is:

$ cp filename filename

For example, to copy the file named ball into another file named ball1, type.

$ cp ball ball1

Cp created a file named ball 1 and copied the contents of the ball into ball1.

To copy directories, we use “-r” in addition to cp. It stands for “recursive”. The syntax for this is:

$ cp -r [directory] [directory]

The “rm” and “rmdir” Commands

We use “rm” and “rmdir” for removing files and directories, respectively. The syntax for these two commands is as follows.

$ rm file

$ rmdir directory

Let’s remove the file “ball” and the directory “wire” we created previously. Make sure you are present in the directory containing both items.

Conclusion

This article went through the ways you can navigate through the terminal in Linux. The commands that were gone through in this guide are the basic ones everyone needs to know about. If you master these commands first, the transition of doing much more complex tasks using the terminal should become easier. You should practice these commands continuously, and you should also try to play with them a bit. It should enable you to learn new tricks making it easier to do certain tasks on the terminal.

About the author

Zeeman Memon

Hi there! I'm a Software Engineer who loves to write about tech. You can reach out to me on LinkedIn.