Bash history command to view session history

Fig.06: View session history in the bash shell using history command

Fig.06: View session history in the bash shell using history command

To view session history in the bash shell type history command:

history
history 20
history | more
history | grep 'command name'

Sample outputs:

 1971  update -y
 1972  exit
 1973  tail -f /var/log/syslog
 1974  update
 1975  tail -f /var/log/syslog
 1976  exit
 1977  update
 1978  df -h
 1979  exit
 1980  ssh-add
 1981  cd /etc/nginx/
 1982  ls
 1983  rsync -av backup:/etc/nginx/* .
 1984  vi options.conf
 1985  /scripts/nginx.rc status
 1986  /scripts/nginx.rc restart
 1987  exit
 1988  update
 1989  ssh-agent bash
 1990  perl -MAcme::POE::Tree -e 'Acme::POE::Tree->new()->run()'
 1991  apt-cache search perl | grep -i tree
 1992  perl -MCPAN -e 'install Acme::POE::Tree'
 1993  apt-get install liblocal-lib-perl
 1994  perl -MCPAN -e 'install Acme::POE::Tree'
 1995  ls
 1996  df
 1997  exit
 1998  update 
 1999  ext
 2000  exit
 2001  history 

Or recored date and time when command was executed:

export HISTTIMEFORMAT='%F %T '
history 20

Sample outputs:

  984  2015-01-23 09:39:10 ps aux | grep java
  985  2015-01-23 09:39:10 htop
  986  2015-01-23 09:39:10 /scripts/lighttpd.rc stop nixcraft.com
  987  2015-01-23 09:39:10 htop
  988  2015-01-23 09:39:10 /scripts/lighttpd.rc start nixcraft.com
  989  2015-01-23 09:39:10 htop
  990  2015-01-23 09:39:10 ps aux
  991  2015-01-23 09:39:10 ps aux | grep light
  992  2015-01-23 09:39:10 w
  993  2015-01-23 09:39:10 htop
  994  2015-01-23 09:39:10 yum update -y
  995  2015-01-23 09:39:10 exit
  996  2015-01-23 09:39:10 yum update -y
  997  2015-01-23 09:39:10 /scripts/lighttpd.rc update cyberciti.com
  998  2015-01-23 09:39:10 /scripts/lighttpd.rc update nixcraft.com
  999  2015-01-23 09:39:10 df
 1000  2015-01-23 09:39:10 exit
 1001  2015-01-23 09:39:10 HISTTIMEFORMAT='%F %T '
 1002  2015-01-23 09:39:13 history 
 1003  2015-01-23 09:39:17 history 20

Examples and usage: A Shell Primer: Master Your Linux, OS X, Unix Shell Environment

Leave a Comment