UNIX & BASH FROM SCRATCH : Part 00 — 10 Productivity Tips To Save Time In The Command Line

Soufiane Ezzaim
IEEE ENSIAS Student Branch
5 min readApr 12, 2020

The shell is the command interpreter in Unix or GNU/Linux, it is a program that executes other programs. It provides us an interface to the Unix/GNU Linux system so that the user can run different commands or utilities/tools with some input data.

Bash stands for “Bourne-Again Shell” ( a pun on “Bourne Shell”, a shell that Bash replaced back at the time) and it is the default shell on many Linux distributions today. It is a command processor that runs in the Terminal.

Bash can also read and execute commands from a file, called a shell script (which we’ll cover later). Like all Unix shells, it supports filename globbing, piping, here documents, command substitution, variables and iteration.
Bash is also a POSIX-compliant shell.

This is going to be a 4-PART UNIX & Bash (Unix Shell) article/ course/ tutorial, or however you want to call it

The series will go as follows :

  • PART 00 : 10 Productivity Tips To Save Time In The Command Line
  • PART 01 : The Basics
    - Navigation : File system, directory stack
    - Create, Delete, Move, Copy files and directories
    - View & Edit files
    - Processes 101 : usage, background, foreground
    - Getting help
    - Miscellaneous, Part 1
  • PART 02 : Intermediate
    -
    Disk & Memory usage
    - Config files
    -
    Environment variables & aliases
    -
    Locating
    -
    Downloading
    -
    Input & Output redirection
  • PART 03 : Advanced
    -
    Permissions
    -
    User & Superuser management
    -
    Processes 102 : Long running processes
    -
    Text processing
    -
    Grep : Pattern Matching
    -
    File management over Secure Shell (SSH)
    -
    Bash Scripting
    -
    Miscellaneous, Part 2

Whether you are a CS student or an IT professional, this series is essential for you, because from beginners to intermediate *NIX OS users, they rely too much on the GUIs, but one day — and that day will definitely come — you will be forced to work solely on a terminal. Eg: You are accessing a remote Raspberry/AWS instance over SSH, you company switched its services to run on Linux servers ..

My Top 10 *NIX Productivity Tips in the command line

These are some *NIX command line practices I follow to work fast, quick, productively and efficiently, after 5+ years of running on a Debian based distros.

I love this kind of productivity tips because, obviously, i’m lazy. And i already know you are too. And because we are two lazy heads let’s skip the intros and head straight to business !

On a side note : By sharing this, I am looking forward is to get some more tips from you guys to enhance my arsenal. So please share how you make most of the shell utilities provided by *NIX operating systems like Fedora, Ubuntu, CentOS, Arch, etc.

1 ) Use “CTRL + R” to look for the last instance of a command

This is a real time saver. If you remember your last command executed sometime back and just want to find that command with the same argument, just press the "CTRL+R" and type words that you had in your last command and Bash will find that command for you.

E.g. You downloaded something with Wget a long time ago and don’t want to use the up and down arrows, and you need that download link, simply hit CTRL + Rand then Wget

2 ) Use !command to quickly execute the previous instance of the command

It always happens that you execute the same command multiple times within a fraction of seconds, before knowing this trick I used to use the up and down arrow for finding the instance which takes a lot of my time, but, after knowing this trick, I just have to just remember the command name.

Use this tip and experience it, It definitely saves loads of time, and it’s very useful on shells other than bash (like csh or ksh) where up and down arrows doesn't give you previous commands.

E.g. !ls will execute your last "ls -xxx" , !vim will open your final file without typing full command

3 ) Use !! to quickly execute the very last command

An extension of the previous tip, used to execute the very last command you have completed. Since it just involves two keystrokes of the same key, it’s amazingly fast. And it gets way more essential on shells that doesn’t support up and down arrows.

4 ) Use “Sudo !!” to execute the last command with superuser privileges

It happens way too often that you fire a command and you need to be a superuser to do that. Everyone had to rewrite that apt-get install with a sudo in it. You can simply hit sudo !!to re execute it on SU mode.

With just these 4, i saved a TON of time on the terminal with how often they occur

5 ) Use “CTRL + L” to clear your terminal

80% of people type clear to clear their Terminal. “CTRL + L” is a win for lazy people like me. Every keystroke counts :)

6 ) Use the magic braces { }

In Bash and most of the other shells {1 .. 5} expands to 1 2 3 4 5. It sounds useless at first but believe me it’s not. Furthermore, as i said previously, every keystroke counts :))

E.g. convert photo.{jpg,png}expands to convert photo.jpg photo.png

7 ) Use ‘ ‘ (space) before command so it wont be logged in the history

If a command contains a password ( or executing it in your friend’s computer 🤷‍♂) ️start it with a space.

E.g. instead of $git config -global user.email "xx@xx.com" use
$ git config -global user.email "xx@xx.com"

8 ) Make use of the output of a command in another command with $( )

As simple as stated

E.g. touch file-$(date -I).txt creates “file-2020–04–11.txt”

9 ) Using pipe instead of firing two commands

Same as 8 but with a twist, this is one of the most helpful commands in Shell scripting. We will talk about pipe in detail later. But it does speed up things a lot.

E.g. history | grep "pip install" instead of stocking the output of historyin a file and then using grep, this will output all the packages you installed with pip.

10 ) Use aliases and define them in the bash .profile or .bashrc file

Have you seen some strange commands working in someone’s machine and not yours, those commands are aliased and were set up in either their .bashrc or .profile file. Always do this for commonly used commands. There are lots of uses of the .bashrc and .profile file, but one of the most important ones is setting up aliases.

To set an alias, add it to the end of your “.bashrc” file, which is hidden in your home directory $ vim ~/.bashrc, and when you finish dont forget to execute $ source ~/.bashrc

E.g. add alias proxyset="export {http,ftp}_proxy="http://00.00.00.00:0000"" to the end of your .bashrc file, hit source, and now simply execute proxyset in your Terminal and it will fire
export {http,ftp}_proxy="http://00.00.00.00:0000" (which sets the proxy)

Hope this helped, let me know what are yours.

Part 01 : The Basics will be published very soon

Side note 2 : A detailed guide on setting proxies in Linux Distros here, it will save you a lot of pain.

--

--

Soufiane Ezzaim
IEEE ENSIAS Student Branch

CS student. Deep Learning enthusiast. NBA fanatic. Mint tea >> Everything