Bash history command with line number on a Linux, OS X, and Unix

Fig.01: Bash history command with line number on a Linux, OS X, and Unix

Fig.01: Bash history command with line number on a Linux, OS X, and Unix

To see your current command line history using bash shell on a Unix-like system, enter:
$ history
Sample outputs:

  811  y=$(for i in $x; do echo "$i/txvip1.simplyguide.org/ "; done)
  812  tar -c $y | ( cd ../old.rsnapshot.backups/txvip1.simplyguide.org/ && tar xv )
  813  rm -rvf $y
  814  ls
  815  cd hourly.0
  816  ls
  817  cd txvip2.simplyguide.org/
  818  ls
  819  du -ch
  820  cd ..
  821  cd txvip3.simplyguide.org/
  822  ls
  823  du -ch
  824  cd ..
  825  ls
  826  y=$(for i in $x; do echo "$i/txvip2.simplyguide.org/ "; done)
  827  tar -c $y | ( cd ../old.rsnapshot.backups/txvip2.simplyguide.org/ && tar xv )
  828  mkdir ../old.rsnapshot.backups/txvip2.simplyguide.org
  829  ls
  830  cd ..
  831  ls
  832  y=$(for i in $x; do echo "$i/txvip2.simplyguide.org/ "; done)
  833  echo $y
  834  tar -c $y | ( cd ../old.rsnapshot.backups/txvip2.simplyguide.org/ && tar xv )
  835  rm -rvf $y
  836  y=$(for i in $x; do echo "$i/txvip3.simplyguide.org/ "; done)
  837  tar -c $y | ( cd ../old.rsnapshot.backups/txvip3.simplyguide.org/ && tar xv )
  838  rm -rvf $y
  839  y=$(for i in $x; do echo "$i/b1.simplyguide.org/ "; done)
  840  tar -c $y | ( cd ../old.rsnapshot.backups/b1.simplyguide.org/ && tar xv )
  841  rm -rvf $y
  842  y=$(for i in $x; do echo "$i/b2.simplyguide.org/ "; done)
  843  tar -c $y | ( cd ../old.rsnapshot.backups/b2.simplyguide.org/ && tar xv )
  844  rm -rvf $y
  845  df
  846  ls
  847  cd hourly.0
  848  ls
  849  cd mysql/
  850  ls
  851  cd txvip1/

How do I save history for a long time?

Edit your own ~/.bashrc file and add the following lines:

HISTFILESIZE=100000000
HISTSIZE=10000
shopt -s histappend

To clean history, type:
$ history -c
$ history -d lineNumberHere
## delete 3 rd command (offset) from history ##
$ history -d 3

Examples and usage: How to delete a single command from history on a Linux/Unix Bash shell