Enjoying the command line

75

Being a Linux sysad and developing automation scripts I would like to share some of the command line tips that I use to increase my productivity.

  • Using ‘history’ command with timestamp :

# export HISTTIMEFORMAT='%F %T '# history | less
988 2015-11-08 19:52:54 vim composer.sls
989 2015-11-08 19:52:54 salt '*' state.highstate
990 2015-11-08 19:52:54 salt * state.show_highstate
991 2015-11-08 19:52:54 salt '*' state.show_highstate
992 2015-11-08 19:52:54 cat /etc/salt/master

  • Repeat previous command quickly using 3 methods

 

 

On command line type !! and then press Enter

On command line type !-1 and then press Enter

Press Control + P will display previous command, press Enter to execute it

  • Run specific command from history

    # history | less

    995 2015-11-08 19:52:54 vim /etc/salt/master
    996 2015-11-08 19:52:54 ps -ef | grep salt-master
    997 2015-11-08 19:52:54 pkill salt-master

    # !996

    ps -ef | grep salt-master
    root 26026 25065 0 20:14 pts/0 00:00:00 grep salt-master
    root 41593 1 0 01:47 ? 00:00:00 /usr/bin/python2.6 /usr/bin/salt-master -d
    root 41594 41593 0 01:47 ? 00:00:00 /usr/bin/python2.6 /usr/bin/salt-master -d
    root 41595 41593 0 01:47 ? 00:00:00 /usr/bin/python2.6 /usr/bin/salt-master -d
    root 41600 41593 0 01:47 ? 00:03:57 /usr/bin/python2.6 /usr/bin/salt-master -d
    root 41601 41593 0 01:47 ? 00:00:00 /usr/bin/python2.6 /usr/bin/salt-master -d