Skip to content

Instantly share code, notes, and snippets.

@nickynicolson
Last active November 22, 2021 12:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickynicolson/321e58eb83769cbe8c356770691a9b21 to your computer and use it in GitHub Desktop.
Save nickynicolson/321e58eb83769cbe8c356770691a9b21 to your computer and use it in GitHub Desktop.
How to access & use command histories

bash

Default behaviour

  • history shows numbered command history, most recent last
  • !n retrieves command number n and executes it
  • !n:p retrieves command number n and places it into the command history without executing it. Up arrow then retrieves the command for editing

shopt

  • shopt -s histverify modifies command recall behaviour so that !n just retrieves the command and does not execute it (ie allows for editing before execution)

ipython

Default behaviour

  • %history displays command history from current session without line numbers

Options

  • -n Include line numbers
  • -g pattern search for pattern (wild cards: ? single character, * multiple characters). As -g searches through full history (not just the current session), an empty -g modifier can be used to retrieve complete command history
  • -f filename output history to file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment