I found another great thing linux provides for the lazy programmers ;) Most of the time we need to repeat the commands we entered in linux terminal and many hardworking engineers typing it again and again ;)

Famous quote “Those who cannot remember the past are condemned to repeat it” preety much applies here when you use commandline mode to operate your machine or working on remote server via ssh.

Linux provides many tools which remembers history and on top of that we can make our life easy.

Usually i work on servers and whenever try to fire few root access commands and it dont allow me!! -_-,feels insulting. Anyway sudo !! is here to rescue you :)

amey@amey-xps:~/$ touch /etc/apache2/apache2.conf 
touch: cannot touch ‘/etc/apache2/apache2.conf’: Permission denied
amey@amey-xps:~/work/blog/codeinventory.github.io/_posts$ sudo !!
sudo touch /etc/apache2/apache2.conf 
[sudo] password for amey: 
amey@amey-xps:~/$ 

Not only sudo, Bang (!) can do may more things <3

Repeating Commands

Repeat last command

!!

Repeat last command that started with x

!x

Repeat last command that has the substring x

!?x

Repeat 10th command in the history file

!10

Repeat 10th from last command in the history file

!-10

Fetching Parameters

Fetch parameters from last command

!!*

Fetch first parameter from last command

!!^

Fetch last parameter from last command

!!$

Fetch third parameter from last command

!!3

Modifiers

Repeat last command substituting foo for bar

!!:s/foo/bar/
!!:p

Happy coding ….. :)

Comments