History Commands

Appendix J. History Commands

The Bash shell provides command-line tools for editing and manipulating a user's command history. This is primarily a convenience, a means of saving keystrokes.

Bash history commands:

  1. history

  2. fc

bash$ history
   1  mount /mnt/cdrom
    2  cd /mnt/cdrom
    3  ls
     ...
	      

Internal variables associated with Bash history commands:

  1. $HISTCMD

  2. $HISTCONTROL

  3. $HISTIGNORE

  4. $HISTFILE

  5. $HISTFILESIZE

  6. $HISTSIZE

  7. $HISTTIMEFORMAT (Bash, ver. 3.0 or later)

  8. !!

  9. !$

  10. !#

  11. !N

  12. !-N

  13. !STRING

  14. !?STRING?

  15. ^STRING^string^

Unfortunately, the Bash history tools find no use in scripting.

#!/bin/bash
# history.sh
# A (vain) attempt to use the 'history' command in a script.

history                      # No output.

var=$(history); echo "$var"  # $var is empty.

# History commands disabled within a script.

bash$ ./history.sh
(no output)	      
	      

The Advancing in the Bash Shell site gives a good introduction to the use of history commands in Bash.


185 visits (1 today, 7 this week, 23 this month, 185 this year)
Uptime: 17:46:48 up 3 days, 23:30, 3 users, load average: 0.00, 0.00, 0.00
3.145.88.155 GET from server z.larrymurakami.com

Saturday, December 21, 2024 @ 5:46:48 PM
z.ServerAdmin@lam1.us