Linux tips and tricks for energy conserving users

Page content

Over the years I learned some useful Linux tidbits that I want to share in this post. Some are useful for the terminal only, others also apply to a typical desktop environment.

Save 33% of your time when performing copy and paste

Normally the copy and paste process involves three steps: select, copy, paste. You can save the ‘copy’ step in linux:

Select the text you want to copy and then move your cursor over to where you want to paste the text and press the middle mouse button.

There are examples where this approach may not work but for 99% of the cases this is a very useful alternative to the three step process.

Entering commands with some help of your computer

The TAB key can save you some time by suggesting what you may want to type. Let’s say that you want to remove a file called test.txt from the desktop. The full command to type would be, assuming that you are at the root of your home directory:

rm Desktop/test.txt

You can save some typing effort by using the TAB key: type rm D and then press the TAB key which would add the letters esktop/ assuming that you don’t have other directories that start with a capital ‘D’. Otherwise it will list the options.

The same applies to the remainder of the command. So after hitting the TAB key you only type tes and the TAB key again. This will likely complete the command for you assuming that there are no other files on the desktop that start with tes.

Entering commands without retyping

When working in the terminal, all commands are stored in a text file called .bash_history in your home directory. This means that you can easily retrieve commands you typed earlier.

Let’s say you want to connect via SSH remotely to a Raspberry Pi in your network, then you would use a command similar to:

ssh pi@1.2.3.4

After finishing with the Pi you would disconnect using the exit command. In future you will not need to fully type this command again but could just retrieve it from history using two methods:

  1. Using the up arrow key of your keyboard.
  2. Using the history command.

Using the up arrow key of your keyboard

This is useful for recently used commands. It let’s you quickly browse through earlier commands. The down arrow key allows you to scroll in the opposite direction. Select by pressing the ENTER key.

Using the history command

This is useful for commands that you used quite a while ago and can still remember bits of. Let’s say that you performed the bluetoothctl command earlier but can’t remember the complete command that you used earlier to connect to a bluetooth speaker. After all, MAC addresses are not easy to remember. You can still search for this command:

history | grep bluetoothctl

This will list earlier times when you used this command. The lowest entry will be the latest use. Note the number of the entry that you want to use again, in my case 5644, and use it as follows:

!5644

The command is then retrieved and can be used again. Edit or just press ENTER.