Top terminal/unix commands and tips to boost your productivity

repeat

As a programmer we tend to use terminal a lot and repeatedly use many commands daily. In todays post we are going to cover tip and tricks to reduce your keystrokes and increase your productivity.
a) Creating Aliases
We tend to do ssh into different servers,run local servers and hell lot of stuff daily before beginning our actual coding.Creating alias for longer commands helps us run our daily commands with lesser keystrokes.
So here are the steps:
1)Open terminal and type vim ~/.bashrc ofr linux or bash_profile in mac.
2)Check if there is following line:

3)If present then quit bashrc and open .bash_aliases file using gedit or some other text editor.
sudo gedit ~/.bash_aliases. If not then continue editing bashrc/bash_profile file itself
4)Enter aliases with following syntax:

alias 91='ssh root@10.130.98.91'
alias http= 'http-server -p 9001'

5)Save the file using :wq in vim or hitting save in gedit.
6)Run source ~/.bashrc
7)Next time you type 91 in terminal it will automatically ssh into required server.

b)Using ! to run last command:
If you ran command like http-server -p 9001 then typing !http will run that command directly.
repeat

You can run last command by simply typing !!.Which is useful when you forget to type sudo before a command. You can also use !$ to use last argument.

c)Using crtl+r to search for commands:
1)Type crtl+r to start reverse-i-search type a keyword that you remember using in the command ans you will get search result.
2)Press enter to run the command.

d)Using pgrep to find pid:
In order to kill/restart a process we usually need pid of the process.Instead of using crazy combination of ps and grep simply use pgrep.

e)Using a combination of history and grep
This allows to retrieve a command you used long time back.

f)Check all ports used by processes in system:

g)Unzipping archive in terminal:
Many times new softwares/packages are downloaded in the extension of .tar.gz
In order to extract it in terminal type:

Here the breakdown is as follows:
x is used to specify that we are extracting archive(c is for compressing)
v is to specify that verbose mode is enabled(gives output while action is being performed)
z is to specify that file we working on is gzipped
f is to specify that we are passing file

h)Use terminator/iterm rather than opening multiple terminals
It is high that you switch to terminal emulators like terminator(linux) or iterm(mac) so that you can open multiple terminals in a single window rather than opening multiple terminal screens.

i)Install and use htop rather than top:
Htop adds some extra good looks and utilities to top command.For system administrators this tool might come in handy.
sudo apt-get install htop

j)Shutdown from terminal:
Last but not the least as many of you might know already use following command to shutdown from terminal:
sudo shutdown -h now
where -h is for halt
-r to reboot
or you alternatively use:
sudo poweroff or
sudo reboot
P.S. Its good to make an alias for shutdown and then use it everyday

Thats it for todays tutorial. Go try some of this commands and happy coding.

Share post-
About Saurabh Mhatre 71 Articles
Currently working in web and hybrid application development