Compilation: the 44 best tricks for Linux

tux super saiyan linux

This article is aimed both for those who have been “messing around” Linux for a while, but still have some doubts or problems with the penguin platform, as well as for those who are more new to learn new things to do in their GNU / Linux distributions. . For them I have compiled this ranking of the best tricks and the most practical.

As you know, the * nix operating systems make intensive use of the console commandsAlthough modern graphical interfaces have emerged and are becoming better and more widespread, these systems have a great dependence on the console for their performance and power. It is good that this heritage from the past is not lost, since it is precisely what weakens other systems.

This is the case of Apple Mac OS X, in which the GUI is seriously committed and the tools to the terminal. This has meant that OS X is not such a used and powerful operating system when it comes to performing certain tasks (eg: for pentesting, like Windows, which despite the number of tools available, they are not exactly fast and powerful …).

Well, as performing tasks in graphic mode is relatively simple, we are going to focus mainly on the tricks to the console and give a series of tips to perform practical, everyday tasks from the console. Although there will also be some practical ideas for other graphic tools.

Optimize your experience with the bash shell:

The Linux console par excellence, bash, it is wonderful to work with, although many find it tedious to work in text mode. To better understand it and work more easily, we will teach you these driving tricks that will make your life and work easier. Linux commands essential to get the most out of your terminal:

  • Command autocompletion: for the console to autocomplete the name of a command or file / directory name just by typing the first few letters, you can use the Tab key. It's simple, type the first letters of a command or address and then press Tab to autocomplete. In case there are several names that match the written letters, you can keep pressing Tab to show more possibilities or just keep writing more letters.
  • Command history: If you doubt the syntax of a command you have used recently or just want to retrieve it to avoid typing it again, you can use the command history that Bash saves (in ~ / .bash_history). To do this you just have to write "history" without quotes and press ENTER. Another option to exploit the virtues of history is to use the up and down arrow keys to “navigate” through the command history and make the stored commands appear in front of the current prompt. You can also use the key combination Ctrl + P and Ctrl + N to do this same task.
  • Search for commands already used: Thanks to the history we have studied in the previous paragraph, you can search for commands used in the past. Just use Ctrl + R for a backward search or Ctrl + S for a forward search. This method is a combination of command and completion history, so we have to write the first letters of the command we want to retrieve.
  • Delete history: If we want to delete the history so that another user on our team does not have access to the commands we have used or simply to delete the file that was already quite saturated with commands due to intensive use of the terminal, you can use "history -c" without quotes and our history is cleared (for the current user). Instead, if you want to erase the history completely, you can use:
cat /dev/null > ~/.bash_history
  • Modify or correct lines already written: If we have searched for a history line or used autocomplete, but we want to update the line for another use or the syntax is simply not adequate, we can use Ctrl + A and Ctrl + E to move the cursor to the beginning of the line or the end respectively. If we want to jump character by character in one direction or another, we can use the left or right arrow keys. On the other hand, if we want to jump from word to word instead of character to character, we can use Ctrl + Arrow (left or right) on our keyboard. Once we reach a point, the character under the cursor can be deleted with the Del key or the one on the left with the Backspace key. If we want to delete the characters from the cursor to the end of the line, use Ctrl + K and then press Backspace. To erase from the cursor to the beginning of the line, use Ctrl + X and then Backspace.
  • Change uppercase to lowercase or vice versa: You can change lowercase to uppercase or the opposite by placing the cursor where we want and then pressing Esc followed by C or L.
  • Copy and paste text on the command line: Apart from the right mouse button, you can use the key combination Ctrl + Shift + C to copy and Ctrl + Shift + V to paste. By the way, Shift is the shift key, but the one under the "Caps Lock" key, for those who do not know. Although it seems silly, sometimes we do not have a mouse to act and it is interesting to know these keyboard shortcuts. For example, this has happened to me on occasion with Raspbian for the Raspberry Pi, in which I did not have a mouse to connect to the board.
  • script: scripts are very practical to automate everyday tasks, imagine you want to see the history, clear the current screen and then erase the history completely. This would require a series of commands and if it is a task that you perform daily, you may be interested in creating a script that does it all at once and automatically and you only have to run it to perform that task. To create it, we write the following text with a text editor and save it with the extension .sh and give it execution permissions. Imagine the example we have put, the text would be:
cat /dev/null > ~/.bash_history
echo "El historial se ha borrado. Gracias.”
  • To execute it, imagine that we have named it, because from the directory where it is located, we write the following and press ENTER (saving us writing the command history to show the history, clear to erase the screen and the cat line to erase the file which saves history, although this script doesn't make a lot of sense, but it's an easy example for you to understand):

Practical tricks and commands to squeeze our terminal:

Once we know how to take advantage of the advantages that bash offers us to obtain a better experience, we can begin to exploit the tools that can be used through it:

  • Know in the directory that I am:
  • Change to another directory:
cd /ruta/del/nuevo/directorio/o/fichero
  • Go back to the previous directory:
cd ..
  • Go directly to your personal directory or that of another user that you specify:
cd ~nombre_usuario
  • Go to the root directory:
cd /
  • Create a directory:
mkdir nombre_directorio
  • Delete directories or files:
rmdir nombre_directorio
rm nombre_fichero
  • List the contents of a directory:
  • View hidden documents in a directory:
ls -a
  • Search for a file in the whole system:
 find / -name nombre_fichero
  • Estimate the space used by a directory:
 du -sh /directorio
  • conduct a backup of a directory in another: imagine that you want to make a backup copy of the / home directory and save it in / temp and that the backup is called copy1:
 dump -0aj -f /tmp/copia1.bak /home
  • Create an ISO image of a quick and easy disk:
 mkisofs /dev/cdrom > nombre_imagen.iso
  • Has your system been locked because of a program in graphic mode? You can force close this failed program to get back to normal with xkill. You just have to type the following and you will see that the mouse cursor has transformed into a cross, with it touch the window you want to force to close and that's it:
  • Do you want rerun the last command joined? Type:
  • Enter a command without it being saved to historyl: you just have to put a space in front of the command you want to exclude from the history list. For example, if you want ls not to be listed in the bash history, type:
  • Get informationn about how to use any command:
 man nombre_comando
  • See the hardware components of our system:
 dmidecode -q
  • Show the ctechnical characteristics of a hard disk:
 sudo hdparm -i /dev/sda
  • Show detailed CPU information:
 cat /proc/cpuinfo
  • Do you need a quick calendar? To get a calendar for a given year, just type the following (eg: to show one for this year):
 cal 2015
  • Or if you want it from a specific month, for example October:
 cal 10 2015
  • Shut down the system at a specified time. Imagine that you are downloading something that will take a while and you want to get out of the house. So that the equipment is not consuming electricity until you return and without leaving the discharge halfway, you can schedule the shutdown at a specific time with this command. For example, imagine you want to turn it off at 08:50:
 shutdown -h 08:50
  • Know our IP: For this we can use the ifconfig command and look for the "inet addr:" field that will determine our IP. It's simple, but this gives us our internal IP. If what we want is the external or public IP:
  • Clean the screen of the terminall not to overwhelm you with so much text and to have a clean environment. It is useful after having executed many commands or with certain tools that return a multitude of textual information collapsing the terminal screen. When you no longer want it, you can leave the shell as new with Ctrl + L or if you wish:
  • Communication in virtual machines: If you use VirtualBOX or VMWare to virtualize another operating system, either Linux or different, you may be thinking how you can link the virtual machine (guest) and the physical machine (host) at the network level or even how to connect two virtual machines to each other. Well, you just have to access the network configuration of the virtual machine and select a NAT configuration to create a direct link between two virtual machines or Bridge to communicate a virtual machine with the physical one. In the first case, you don't have to do anything, but if you select a Bridge mode, you will have to configure the IP of the guest so that it is in the same range as the physical host. For example, imagine that your physical machine has an IP (you can check with ifconfig) and that the virtual machine has another Linux distro. Well, you should open the terminal of the virtual machine and type "ifconfig eth0 new_IP" without quotes and replacing new_IP with the IP you want (remember also that if you are using another network device other than eth0, you have to specify it). This new IP must be in the same network segment as that of the physical machine, so it has to look like 192.168.1.X, where X is any number from 0 to 255. For example, this would work in this case:
 ifconfig eth0
  • Silence annoying error messages: I advise first to solve or monitor the problem and see that it is not something serious. But sometimes, some punctual or harmless errors generate an error file that will cause an annoying message to appear warning us of the problem and asking to report the problem to solve it. If you want to avoid that annoying message of "A problem has been detected ..." or similar, you can type the following:
 sudo rm /var/crash/*
  • Hard drive at capacity limit (free up space): to free up space you can use for example the following sequence of commands (this will delete unnecessary files that take up space without being precise)
 sudo apt-get autoclean sudo apt-get celan sudo apt-get autoremove
  • Check the available and used space of the hard disk: To do this, we can use a simple command that gives us data on the free and used space of the present partitions, including the percentage:
 df -H
  • Find out the libraries a program uses: For example, imagine you want to see the libraries that the "ls" program depends on:
 ldd /bin/ls
  • Search and delete all files with a certain extension: imagine you want to delete all images with a .gif extension from your system (whatever their name is). Type:
 find -name *.gif | xargs rm -rf
  • Know which ports we have open: To know which ports we have open we can use these two commands, one for TCP and the other for UDP:
 nmap -sS -O
nmap -sU -O
  • Know what shell we are using: as you know there are several, although bash is the most widespread there are others. To know which shell we are working with, you can type the following command that returns its name:
 echo $SHELL
  • Information about the kernel version, architecture and distro: We can know information about the version of the Linux kernel that our distro uses, as well as the architecture of our processor and the distribution that we use. You just have to type:
 uname -a
  • Detect if our system is in danger due to the existence of rootkits: rootkits are malicious tools as you know, these tools allow root access to malicious users. To detect if our system is infected by one, we downloaded this package and then (from the directory where the downloaded file is located, remember to use cd to go to it):
 tar -xvf chkrootkit.tar.gz
cd chkrootkit-0.49/
make sense

I hope it has been helpful for you. Do not forget to comment to give your opinion and if you wish, ask us to add some other trick that you find interesting. We are open to your requests.

More information and tutorials from our blog - The best Linux alternatives to Windows programs, How to install any package on Linux

The content of the article adheres to our principles of editorial ethics. To report an error click here.

6 comments, leave yours

Leave a Comment

Your email address will not be published. Required fields are marked with *



  1. Responsible for the data: AB Internet Networks 2008 SL
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   Stranderson said

    Copying and pasting text with the keyboard is made more comfortable with:

    Ctrl + Insert -> copy
    Shift + Insert -> paste

  2.   Pepe Matthias said

    with the mouse you select and the central button you hit. easier impossible.

  3.   Richard Moon Fuentes said

    Excellent contribution, it helps me a lot for the computer science career to which I am going to study

  4.   Online computer stores said

    What a good contribution! I will link to it on my web pages.

  5.   kike said

    great summary, thank you very much

  6.   Jorge Luis Arellano Zubiate - Luckord said

    Thanks a lot…
    The commands you mention are very useful.
    Greetings from Lima, Peru
    - Linux Mint 20 -