The power behind the Linux terminal

t4inha

Anderson Bosa

Posted on March 15, 2021

The power behind the Linux terminal

Table of contents

Introduction

Search, differentiate, analyze, share, unzip, encrypt a file, access a cloud computer, convert a video to gif, etc. These are some of the possible things to do with the command line.

The terminal is a magic wand to interact with the computer's resources. Allowing interaction practically and flexibly, which makes it a very powerful tool.

Basically on all operating systems (e.g., Windows, Android, Mac and etc.), the command line is a text interface to communicate with the computer (or device).

image

Also known as shell,console, prompt, and among other names, the terminal can be frightening and confusing at first contact. Like all new knowledge, in the beginning, there may be more difficulties. However, as we overcome these barriers, we are faced with our evolution.

Knowing how to use the terminal can be essential when trying to deal with the problems that pop up daily as an IT professional. I read a post the other day when the author said something that itched me:

If you are a Linux user, Terminal is probably the most powerful tool you have ever had. But the problem with Terminal is that you need to learn how to use it if you want to benefit from it. - Mauro Garcia

me: YYEESSSS

image

It scratched me to want to share a little of what I learned out there with my colleagues. And then I brought it here too. Knowing some of these things makes a difference in my day-to-day life as a software developer.

I hope I can help you feel a little more comfortable the next time you need to open the terminal.

But before we start ... a tip for non-native speakers of English:

Thinking in English helps to assimilate the commands!

If you are like me, non-native English, I believe you will understand better what I mean.

Let's understand with an example, the command pwd is for Print Working Directory. What in my language (Brazilian*) would be something like edt (Write the Working Directory).

I think this example helps to make it clear that thinking about what you want to do in English helps to assimilate what is being done. Helping to internalize what you want to do. As with ls (list) or cd (change directory).

Basic commands

Here are some practical commands to know. I used a command to describe them, we'll see which one is ahead.

  • mv - move (rename) files
  • cp - copy files and directories
  • rm - remove files or directories
  • ls - list directory contents
  • pwd - print name of current/working directory
  • mkdir - make directories, create a directory
  • rmdir - remove empty directories, delete a directory
  • cat - concatenate files and print on the standard output
  • tac - concatenate and print files in reverse
  • more - file perusal filter for crt viewing
  • less - opposite of more
  • chown - change file owner and group, change ownership of a file
  • chmod - change file mode bits, change permissions of a file
  • chattr - change file attributes on a Linux file system
  • curl - transfer a URL
  • wget - The non-interactive network downloader.
  • tar - an archiving utility
  • gzip - compress or expand files, sort of Linux 'WinRar'
  • ping - send ICMP ECHO_REQUEST to network hosts
  • sort - sort lines of text files
  • filter - cups file conversion filter interface
  • uniq - report or omit repeated lines
  • history - GNU History Library
  • top - display Linux processes
  • ps - report a snapshot of the current processes.
  • pkill - look up or signal processes based on name and other attributes
  • ssh - OpenSSH remote login client
  • git - the stupid content tracker

All commands can be concatenated in the terminal, it is a matter of knowing how to do them. The power to concatenate commands gives us incredible power with the command line.

For example, let's say we want to find which commands are in the history, but there are a lot of repetitions and irrelevant information at the moment (like the parameters) ... We could do it by unifying 4 commands in the following order: history | cut --delimiter=" " -f 4 | sort | uniq.

Or maybe you want to use an image as an icon ... You could:



# 1) download the image and 2) encode it on the fly.
curl https://duckduckgo.com/i/bfc48a09.jpg --output - | base64 -
# is now ready to use in an HTML tag 😎

Enter fullscreen mode Exit fullscreen mode




Here is precious witchcraft for the next time your virtual memory runs out:

  • xkill - kill a client by its X resource. Basically when you proclaim this command the point of your mouse will become Alvo Dumbledore's wand. Wherever you (left) click, the thing where you clicked dies.

image

Commands that help us help each other

  • whatis - display one-line manual page descriptions. It helps to identify the purpose of any command in seconds. This was the command I mentioned above.
  • which - locate a command.
  • whereis - locate the binary, source, and manual page files for a command.
  • man - the program manual. An interface to the system reference manuals. This is the way to anything. The relevant information about the program will be in the manual.


# Try on your terminal
$ whatis whatis which whereis man

Enter fullscreen mode Exit fullscreen mode




Have your own Snippets

A snippet is a function designed to serve a purpose. In Bash / shellscript we have the famous "one-liners". I recommend having them for two reasons:

  1. Fear: they obviously scare. A chain of interconnected commands to serve a purpose? I find it incredible and terrifying. ~~ Whenever I find myself running a I think that if it breaks in half it will delete my entire system 😅. ~~ With that you will be cautious with the terminal because even a hammer is bad if it is not used correctly.

  2. And news: you will be exposed to new solutions and also to new ways of using what you already know.

I will leave some references on the wheel, places where we can check out these "one-liners". 😆

Practice!

The best way to learn and assimilate is by doing. So let's put into practice what we've seen so far through some exercises. For this we will use Capture The Flag Bandit from OverTheWire.

Capture The Flag is a style of competition that involves several skills to solve challenges related to infosec, to capture the flag (usually a code), and scoring. In Bandit the CTF levels take place on a remote machine, where we will connect via the terminal via ssh.

Bandit will help us to put into practice and polish our skills with the Terminal. From here on, it's up to you. Good luck!

Feedbacks 💙

  • Was something missing, or was it wrong, or do you have any suggestions? Please let me know your opinions!

One-liners

Credits, fonts and articles:
💖 💪 🙅 🚩
t4inha
Anderson Bosa

Posted on March 15, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related