history
Display and manipulate command history.
Source: src/execution/builtins.f90, src/io/readline.f90
Synopsis
history [n]
history -c
history -d offset
history -a|-r|-w [filename]
Description
The history builtin displays and manages the command history list.
Options
| Option | Description |
|---|---|
n | Show last n commands |
-c | Clear history |
-d offset | Delete entry at offset |
-a | Append new entries to file |
-r | Read history from file |
-w | Write history to file |
Usage
Display History
history # Show all
history 10 # Show last 10
Clear History
history -c
Delete Entry
history -d 42 # Delete entry 42
File Operations
history -a # Append to HISTFILE
history -r # Read from HISTFILE
history -w # Write to HISTFILE
Examples
Search History
history | grep git
Re-run Command
!42 # Run command 42
!! # Run last command
!git # Run last git command
Save Current Session
history -w ~/.history_backup
Load Another History
history -r ~/.other_history
Configuration
HISTFILE
export HISTFILE="$HOME/.fortsh_history"
HISTSIZE
export HISTSIZE=10000 # In memory
HISTFILESIZE
export HISTFILESIZE=20000 # In file
HISTCONTROL
export HISTCONTROL=ignoredups:erasedups
Options:
ignorespace- Skip commands starting with spaceignoredups- Skip consecutive duplicateserasedups- Remove all previous duplicatesignoreboth-ignorespace+ignoredups
Exit Status
| Status | Condition |
|---|---|
| 0 | Success |
| 1 | Invalid option or offset |
Notes
- History persists across sessions via HISTFILE
- Use
!nto recall command n - File ops require HISTFILE to be set
See Also
- History - Full history documentation
- Line Editing - Navigation