Do you know how to work a Linux Command Terminal?
This post is also available in : Spanish
Command terminal: How to do more in less time!
Something that the Linux kernel inherited was the command line interface (shell): in Unix® it was called Bourne Shell (written by Mr. Stephen Bourne) and it is called Bash which stands for the Bourne-again shell, something like “terminal rebirth”, playing with the surname of the famous computer. Let’s see today the Command Terminal in Linux!
It turns out that every day and at every moment we practically use a Command Terminal. How is this possible?
Almost a Command Terminal
Strictly speaking, any software that allows us to enter commands is a Command Terminal, but all the data we enter emulates the original behaviour. The main difference is that, generally, we do not press the ENTER key nor do we have an inductor or prompt… And what the hell is all this?
To simplify, we have used the concept of Command Terminal to encompass several definitions. Don’t forget what we mean when we say Command Terminal ;-).
Command terminal in practice
Every time we use any program, unless it is a video game, we will need to enter information using our keyboard. Of course, this is less used every day because we can already dictate to our computers and write for us and thanks to the graphical interface of modern operating systems will often suffice with a pointing device (mouse or our fingers on a touch screen) or the use of both methods.
But if we want to finish our work quickly, there’s nothing better than typing. What we will name you is useful both for entering data and for a Command Terminal:
- Our screens have a width limit, that would be our line of work.
- Already in that line, indicated by a cursor, we can begin to write. Each word is separated from each other by one or more spaces. The quick way to go back or forward to each of them to correct or add something is with the CONTROL keys on your keyboard (in the lower left corner of most keyboards), plus the left or right arrow on your keyboard. This combination is denoted as CTRL+← or CTRL+→, respectively.
- We also have a key dedicated to go to the beginning of the line, Home, and its counterpart, End.
Come on, let go of the mouse! Working this way, just with the keyboard, may seem intimidating, but it’s just a matter of practicing a little. It’s like riding a bicycle! Once we try it and learn, we won’t be able to live without them.
Opening a Command Terminal
To practice the previous section, depending on your Linux distribution, generally with the key combinations CTRL+ALT+T will be more than enough. But if you really want to move forward, with ALT+F2 you can invoke your favorite Command Terminal – almost always every Graphical User Interface includes yours as well as Bash-, including the powerful GNU Emacs, a text editor that allows macros that lighten our work in the Command Terminal (we write less and do more).
A widely used command is ls which allows you to list files and directories; entering this command and pressing Enter will already be recorded in our history of issued commands (correct or not). With the date up or down we will be able to “navigate” and reuse the commands or complete lines. Another command widely used in monitoring is ping which serves to test the connectivity between two computers; as for my favourite text editor is nano; in the following figure we execute the three commands:
With some arrows in pink we emphasize the command history in this case with the numerical parameter to see the last three orders and their identifying numbers: then look at these digits and placing as prefix the symbol of closing of admiration plus the wished number we will be able to execute again this previous line. No more forgetting for our daily routine!
We are most forgetful
The true power of the Linux Command Terminal is that one command can deliver its results to another; this is called STDIN, STDOUT and if STDERR error occurs. All three make up the Standard Entrance; again let’s go to practice:
history 3 | grep ls
Here the history command gives the last three lines to the grep command which in turn filters and displays only the lines containing that string. This is useful to help retrieve our orders.
We have already seen that !+n allows us to execute the desired line; with !! we will repeat the last line… But do we do the same with an up arrow and an intro? Yes, but here comes the interesting thing with an example: if we forget to execute a command as superuser or root we simply introduce sudo !! more quickly. What do you like about this?
Also with CTRL+R you can search interactively: type a few letters and the last line containing those letters will be returned to you; pressing CTRL+R again you will see the previous coincident and so on (you can even delete with the key ⌫ Backspace or add more characters to the search). Once the desired line is located, press the Esc key and you can edit and reuse the command; with CTRL+G we cancel the search and restore the current line.
“Copy and paste” is a familiar action for anyone who has touched a computer; to do this you must first learn how to select a text. In the graphic interface we can select by pressing SHIFT+CTRL+FLECHA and pressing CTRL+X to cut and CTRL+C to copy. In the Command Terminal there are much more efficient commands:
- CTRL+U: to cut from the cursor to the beginning of the line.
- CTRL+K: to cut from the cursor to the end of the line.
- CTRL+W: to cut a word to the left.
- CTRL+Y: to paste what is in memory.
- CTRL+_: to redo the last action.
- CTRL+C: cancels the editing or the command in execution.
Let’s explain how Pandora FMS uses the Command Line Interface: with a file made in Perl language we can create scripts that execute our most common commands, such as creation and modification of agents, modules, alerts, etc. We will quickly understand the general syntax with what we have explained about the Standard Entry:
And now that you know better the Command Terminal and its history, how about taking a few minutes to test it in Pandora FMS? Or, if you want to get straight to the point, you can also discover what it is and what Pandora FMS can offer you, going here: http://pandorafms.org/features/features/
Or you can also send any query you have about Pandora FMS for more than a hundred devices. You can do that in a very simple way, thanks to the contact form that can be found at the following address: https://pandorafms.com/contact/
Pandora FMS team will be happy to assist you!