Efficient use of command line history using !! and !
Double exclamation i.e, ‘!!’ represents the last run command on the bash. Here is an example :
$ uname -r
Now, let’s come to single exclamation i.e, ‘!’ . Unlike ‘!!’, through single exclamation ‘!’, we can access any previously run command that exists in
command line history. Here are some examples :
14 uname -r
 Delete all files in a directory except some (with particular extensions)
Suppose you have a directory with lot of files and you want to delete all the files except some of them (with particular file extensions).
1.cpp find.c inherit.c settings.py spiral.py
2.cpp helloworld.c search.php sort.py
Now, you want to delete all the files except .c and .py files.
$ rm !(*.c|*.py)
find.c helloworld.c inherit.c settings.py sort.py spiral.py
 Make a command not to show up in the output of ‘history’ command
Sometimes you would want to run a command but do not want it to appear in the output of history command. You can achieve this by inserting a space before you type the
command. Note that here I put a space before the ‘df’ command.
$ vim 1.c
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda10 44711000 3709692 38730076 9% /
udev 1968528 12 1968516 1% /dev
tmpfs 792108 1024 791084 1% /run
none 5120 0 5120 0% /run/lock
none 1980260 240 1980020 1% /run/shm
cgroup 1980260 0 1980260 0% /sys/fs/cgroup
. . .
1 rm .bash_history
3 vim 1.c
The df command was not captured in the output of history command.