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:
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:
For example, you must type the following if you want to access the “Downloads” folder.
Or you could access it with the following.
To go to the home directory, use this command:
To go to the previous directory, do this:
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:
For getting into the home directory, add another “../”
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.
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.
If you prefer to see the contents of the directory in an extended form.
“l” over here signifies “long”.
To view files arranged according to time of modification, type the following.
The “mkdir” Command
To create new directories, we use the “Make Directory” or the “mkdir” command. The syntax for this command is given below.
For example, to make a directory named “wire” in your home directory.
Make sure you are in your home folder.
To make an extended directory, use -p with mkdir.
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.
For example, just use the following to create a file named “doc1” inside any directory.
To create multiple files at once in the same directory, type the following.
You can also do this by using the absolute address.
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.
For example, we type the following to move a file named “ball” to a directory named “wire”.
If you want to move the file “ball” to your home directory, use the “.” operator at the end.
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:
For example, to copy the file named ball into another file named ball1, type.
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:
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.
$ 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.