Pages

Wednesday, December 25, 2019

Linux terminal commands you might not know

In the day-to-day of the system administrator or the increasingly popular DevOps, using the terminal is something that consumes much of our time, whether it is performing normal tasks, automation tasks or during system configuration processes.

We spend a lot of our time in front of a terminal and we must learn the most interesting commands that help us perform tasks faster and more comfortably, detecting in which we spend more time (or in which tasks we take longer), to find ways to simplify and Take advantage of our time.

In this article , we will discuss interesting commands to simplify our life in terminals of GNU / Linux systems, also applicable to WSL (Windows Linux Subsystem), where we can have a native Linux terminal on Windows systems 10.

Fuck


a great command with which it will be very difficult for you to continue living from now on: fuck. This command (an alias of thefuck), allows us that when we write a command in the terminal and have a typo, simply by typing fuck, it will try to correct the previous command to its version without errors.

When writing fuck we will see a line where we are giving the most likely matches and we can move up and down, or press ENTER to send the suggestion or CTRL + C to cancel it.

Alternatively, keep in mind that if we write !! in a terminal, the previous command is sent again. Many times, when we forget sudo in a command, it is enough to write sudo!
| thefuck


TIV: Terminal Image Viewer

 

On multiple occasions, we are connected through an SSH connection where we do not have a graphic environment or we only have access to a text terminal. Using tiv (Terminal Image Viewer) we can "view" images or graphics from the terminal without having to download them to another computer or start a graphical environment. TIV interprets the image specified in a low resolution version in text mode, where we can get an idea of ​​what the image is like.

You can also set a * .jpg to show a gallery of the images to be displayed. TIV incorporates some interesting options or parameters, such as:


    -256: Reduces the number of colors to 256. Useful in cases where colors are displayed incorrectly.
    -w: Sets the maximum character width of the image.
    -h: Sets the maximum line height of the image.

        If TerminalImageViewer (TIV) does not convince us, we can try it with timg or terminal-image, the latter available in NodeJS.

     TerminalImageViewer


htop

 A very famous and well-known command is top in GNU / Linux. It is a Linux process manager, which shows the top of processes that consume more resources (memory, CPU, etc ...). Htop is a well-known tool that substantially improves the classic Linux top, adding a very well-achieved color syntax, and a series of very extensive customization options and parameters.


Among its options, there is the possibility of searching or filtering, displaying an advanced color scheme that gives more information on the current consumption of the system, sorting by specific columns or collapsing the names of repeated processes, among many other options.

    htop
    | htop


Googler / ddgr:Searching from terminal

 Googler and ddgr are two tools for searching search engines such as Google or DuckDuckGo from a terminal. Using the -n X parameter you can specify the number of results, if you just want to search for something specific, or with -j open the first result in a browser. You can also browse the results interactively with the n and p keys or return information in JSON format with the --json parameter.



Googler comes in the Debian 9 Stretch apt repository, but ddgr is not, so if you want to install it, follow these simple steps:
  • wget https://github.com/jarun/ddgr/releases/download/v1.4/ddgr_1.4-1_debian9.amd64.deb 
  • sudo dpkg -i ddgr_1.4-1_debian9.amd64.deb

 | googler
 ddgr

Exa

 Exa is defined as a modern replacement for ls. It is a command created with Rust makes a little easier reading lists of files in linux, displaying colors and adding some extra features like git status of a folder or view folders in a tree format.
For automatic installation, Rust and its installer are required to be installed. If you don't have it, you can always download the binary and install it on our system:
  • wget https://github.com/ogham/exa/releases/download/v0.8.0/exa-linux-x86_64-0.8.0.zip unzip exa-linux-x86_64-0.8.0.zip  
  • sudo mv exa-linux-x86_64 /usr/local/bin/exa

 Exa
Exa

  dtrx: Automatic archive extractor

 Another of the usual problems when dealing with compressed files is that, depending on the format you have to use a different tool or specific parameters. Special mention in the case of tar, as the great XKCD tells us in 1168: Tar, although in recent versions it has been tried to solve in a certain way.

The dtrx tool aims to solve this problem, giving us a unified system to extract any type of file: tar, zip, cpio, deb, rpm, gem, 7z, cab, lzh, rar, gz, bz2, lzma, xz and even some files self-extracting exe.

With the -l parameter we can list and view the contents of the compressed file before extracting it.

     Dtrx
     Dtrx

 vnstat: Network consumption statistics

 In many cases we are interested in knowing how much bandwidth we have consumed in our equipment (or the equipment we use as a server) during a specific period of time. Vnstat is an excellent tool that shows us the same thing: how much bandwidth we have consumed during a certain time.

We can see the bandwidth transfer by hours, days, weeks, months or even live, among other options.

     vnStat
     vnStat

 micro: Intuitive text editor

 One of the most traumatic points when starting to use Linux terminals are the most used text editors. VIM is one of the most versatile and powerful, but also one of the most feared.

Many times, you start using nano, a much simpler editor than vim, but also much simpler. An alternative to these two is micro, a very intuitive text editor that even preserves as standard the usual key combinations we use as CTRL + S to save, CTRL + Q to exit, CTRL + U to undo, CTRL + C to copy and CTRL + V to paste.
 In addition, we can also use it through pipes to send the output of a command directly to the editor, change color schemes, and many other interesting details.

To install it, we just have to write the following:

curl https://getmic.ro | bash
sudo mv micro /usr/local/bin
 
 Micro Editor
| Micro

  tmux: Terminal Multiplexer

Tmux is a terminal multiplexer, or what is the same, a tool that allows you to divide a text mode terminal into several different terminals. Tmux offers two main advantages for which it is already worth working with it: make better use of space and recover lost sessions.

The first is the most obvious, since being able to divide into several terminals, you can take better advantage of the space and work while seeing information from another command. The second is very interesting. Many times the remote connections by SSH are interrupted by connection problems, micro cuts, sudden closures or similar errors. If we have an open connection with tmux and it is interrupted, we just have to reconnect and write tmux attach to recover the session as it was.
 Once a session with tmux is opened, press CTRL + B and then% to divide the terminal horizontally or CTRL + B and then "to divide the terminal vertically. In the same way, you can continue dividing the divided terminals.

More interesting details:

    CTRL + B y?: Moves to the terminal on the left. Idem with the rest of the cursors for other directions: up, right or down.
    CTRL + B and ALT + ?: Expand or reduce the current terminal to the indicated address.
    CTRL + B and CTRL + O: Rotate the site terminals.
    CTRL + D: Close the current terminal.

If you don't like tmux, you can try Oh My Tmux !, a special configuration to make it more beautiful and comfortable, or other similar alternative managers such as byobu or dvtm.

     tmux

Autojump: Jump through folders more efficiently

With autojump we can improve the classic way of accessing directories with cd. Usually, we usually write the folders or directories in the form of relative paths through which we are accessing, or even the absolute paths when we want to "jump" to a specific folder.

This becomes somewhat tedious when we have to be moving through several folders intermittently. With the pushd and popd commands, we can use a stack to store or retrieve the most used folders, but autojump manages this in an even smarter way, since we only have to write part of the name of the folder we want to access and It will be based on the folders in which we have been most, since it maintains an internal database with this information.
To install it, we just have to do a sudo apt-get install autojump and execute the following order. /usr/share/autojump/autojump.sh, which will activate an alias j to use autojump.

    | Autojump

No comments:

Post a Comment