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

OptionDescription
nShow last n commands
-cClear history
-d offsetDelete entry at offset
-aAppend new entries to file
-rRead history from file
-wWrite 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 space
  • ignoredups - Skip consecutive duplicates
  • erasedups - Remove all previous duplicates
  • ignoreboth - ignorespace + ignoredups

Exit Status

StatusCondition
0Success
1Invalid option or offset

Notes

  • History persists across sessions via HISTFILE
  • Use !n to recall command n
  • File ops require HISTFILE to be set

See Also