How to Learn and master the Linux Terminal? Many people want to know the truth, they are worried that how much time is required to learn and master Linux.
It is true that Linux distributions have changed a lot in recent years. Today, practically anyone can be used from a window-based interface very similar to that of Windows. No user should be afraid or think that Linux is a complicated operating system. However, it is true that, if we want to get the most out of it and make the most of it, we must use the Terminal. And this is where the fear of many users is born.
What is Linux Terminal?
The Linux Terminal is a console, similar to CMD or PowerShell (but much more advanced than both), used to allow more advanced and technical users to control even the smallest detail of the operating system.
From this console, we can run all kinds of binaries, although its purpose is to run those that do not have a graphical interface and that must be used through commands. As in other operating systems, we can run any binary or script directly from its directory.
In addition, Linux also has a PATH where we can save binaries and run them without having to navigate to their directory. By default, the Linux PATH consists of the following directories (where the command is searched in order):
The Linux terminal is based on a scripting language known as Bash, inherited from sh, the Unix console. We can run scripts from the console, run binaries, and perform all kinds of tasks. Unlike Windows, Linux has a large number of very advanced tools on its terminal to manage and control the operating system.
Everything we do from an interface, we could do it perfectly from the terminal. Although in a more complicated, long and less intuitive way.
How to open a Terminal in Linux
Each Linux distro has its own quirks, so this may change. We are going to use Ubuntu, the distro balanced between performance, usability, security and stability most used in the world for the examples.
There are two ways to get to the Ubuntu terminal. The first of these is launching a TTY, or workspace without a graphical environment. We can run 7 terminals at the same time in this way. From 1 to 6, none have a graphical interface. The only one with GUI is the TTY7.
To change TTY in Linux, we must use the keyboard shortcut Control + Alt plus the key, from F1 to F7, of the TTY that we want to execute.
And if we want to use the terminal as such, we can find a dedicated app, which runs in a window, within the applications panel of our distro. In the case of Ubuntu, for example, we can find this terminal in the program drawer of the GNOME graphical environment.
Basic commands for Terminal
Although it may seem complicated to use, we should not be afraid of the Linux console. We can use it to manage the most advanced parts of the operating system (such as daemons that run together with system), to running normal applications.
Each Linux Program has a name associated with it, the name of its package. Therefore, if we enter the name of the said package in the Terminal (for example, Firefox), we can see how the browser opens directly. Even to open a web page directly.
This is the simplest and most basic of the Terminal. But there are also many other essential commands that we must know and that will help us to control this console much better.
Move through the directories
Something essential to be able to start defending ourselves with the Linux terminal is knowing how to move through the different directories. The first thing that will catch our attention is the ~ symbol that appears to the left of the commands. This indicates the home directory (/home/user) where we started.
CD command for Linux Terminal
Using the command “cd” we can change the directory and move through the entire tree of our hard disk. We can go to the folder «Downloads» inside «/home/user/» by executing the command:
We can also use full paths, like:
cd / home / user / Downloads
ls command for Linux Terminal
Once we are in the directory we want, we can use the “ls” command to see a list of all the files in that directory.
mkdir command for Linux Terminal
This command allows us to create a new folder in the directory where we are located. We must execute this command followed by the name of the new folder that we want to create, for example mkdir software.
cp command for Linux Terminal
With this command, we can copy a file from one directory to another. We can use it to copy a file from the current directory to another directory, or by entering two absolute paths:
- cp file / home / user / Documents
- cp / home / user / Downloads / home / user / Documents
We can use this command to copy a directory and all its files from one place to another. For this we must use the -R parameter as follows:
cp -R / home / user / Downloads / / home / user / Downloads-Copy /
mv command for Linux Terminal
This command works the same as the cp command we just saw, with the difference that instead of copying the file, it moves it (that is, it disappears from the source). This command can also be used to rename a file. We just have to move it to the same directory with a different name. For example:
mv file1 filenew
Of course, we can also use it to move directories:
mv / source-directory / / destination-directory /
cat command for Linux Terminal
It is worth mentioning that when using Linux from your terminal, this is also one of the most used commands for years. And it is that to give us an idea, it will not be of much help when listing the content of a file in the standard output that we have configured in the system.
But that’s not all, but it also proposes other basic uses but no less useful in Linux. Therefore, in order to be able to execute this command, we only have to type the command cat followed by the name of the file and its corresponding extension. These are some of the examples that we can use and that will help us to get an idea of its nomenclature and mode of use:
- cat file.txt.
- cat> filename: to create a new file from scratch.
- cat filename1 filename2> filename3: merge files 1 and 2 and on the other hand store their output in file 3.
rm command for Linux Terminal
Finally, we are going to talk about the rm command. This allows us to delete any file using relative paths (that is, a file within our current path, which we see with ls), or absolute paths, moving us to the directory where the file is saved.
- rm filenew
- rm / home / user / Downloads / newfile
We can also use it to remove entire directories:
rm -rf / home / user / directory
pwd command for Linux Terminal
This simple command has a single (and useful) purpose: to show us the directory in which we are working. Very useful when we have moved (we remember, with CD) through several subdirectories and we do not remember exactly which one we are working on.
Linux also has a wide variety of commands that allow us to control most aspects of the operating system. Some of the simplest and that we are worth knowing are:
- date: displays the date and time.
- cal: shows us a calendar.
- uptime: shows the time the computer has been on.
- uname –a: shows us the kernel version.
- whoami: tells us what our current user is.
- chmod: allows us to change the permissions of any file or directory.
- chown: allows us to change the authorship of any file or directory.
- mount: allows us to mount units (hard drives, USB, memory cards, etc.) in a directory.
- clear: allows us to clean the Terminal to work with it in a more orderly way.
For user management:
- su: allows you to log in as root from the current session.
- exit: close the open root session.
- adduser: allows us to add a new user to our Linux.
- passwd: allows us to change the password of the user that we specify.
We can control the processes that run on our distro with:
- top: a simple process viewer with which to see everything that is running on the system.
- kill ID: allows us to kill any process from its identifier.
- ps: shows all running processes.
- free: shows us information about the used and free RAM.
Finally, we also have some commands to control the startup and shutdown of the PC:
- halt – Stops all system processes and shuts it down.
- shutdown: allows us to shut down the PC in one minute. We can use the -R parameter to specify the time, in minutes, to shut down the PC. And with -H now we can skip the minute of waiting and turn off the equipment directly.
- reboot: reboot the computer.
Install and uninstall programs
From the Linux terminal, all kinds of programs are also usually installed and uninstalled. This is where each distro changes, since the package manager that is included by default in Ubuntu is not the same that we can find, for example, in Arch Linux.
In Ubuntu, the package manager that we find is APT. With it, from Terminal, we can download, install, update and remove any software package. Distros come with quite complete software repositories, so if we know the name of the package we can easily install it as follows:
apt install firefox
To remove an installed program, we can change “install” to “remove” (to remove only packages) or “purge” (to remove the package and all the settings and other residual files):
apt purge firefox
We must also know how to add new repositories to Ubuntu and how to update them to always have the latest versions of the software.
Finally, from the console, we can also download and install the latest updates for our Linux distro. Following the example of Ubuntu, we can download the latest updates for our version of Ubuntu (both system and installed applications) with:
- apt update
- apt upgrade
And if there is a new version of Ubuntu (the ones that come out every 6 months), we can download and install it with the following commands:
- apt update
- apt do-release-upgrade
Some distros may use other package managers, such as pacman, or make us go directly to installers such as “dpkg”, “yum” and “rpm”.
We can also use the Linux Terminal to make inquiries and requests over the Internet. The most known, used and useful commands that we can find within this category are:
- ifconfig: allows us to see a list with all the IP addresses of our PC.
- ping [server or IP] – Pings a server (Google in our example), checks for a response, and measures latency.
- traceroute : trace the complete path from our PC to the server.
- whois [server]: gets information about a domain (in our case, Google).
- wget [url]: allows us to download the file that we specify in the URL.
- ftp [server or IP]: allows us to connect to an FTP server.
- iptables : allows us to open the native Linux firewall administrator.
All distros usually bring at least one program to be able to use the Linux terminal from the graphical environment. In addition, all of them have one, or more, TTY that allows us to use our distro without the graphical X server, exclusively in the terminal.
But on the web, there are a large number of terminal programs, each with unique characteristics so that each user can choose the console that he or she likes best or best suits their needs or way of working.
Without a doubt, the best known and most used. This console is part of the tools that are included in the Linux GNOME desktop, a desktop that comes by default in many distros, such as Ubuntu. Simple, fast and light, this terminal fulfils its function and is more than enough for most users.
sudo apt install gnome-terminal
Another very popular terminal within Linux. This comes installed together with the X Window server and offers a simple TTY as well as powerful and, above all, very light. This console will always be available in all Linux distros that we can find, as long as they have a graphical server.
sudo apt install xterm
Just as GNOME Terminal was the console for the GNOME desktop, Konsole is the one that comes by default on KDE desktops. In addition to having a large number of customization options, it also has support for tabs and bookmarks, which makes the work easier for users.