githubEdit

Command History & Substitution

Command History

  • To show previously executed commands use the history command

history

history
  865  find / -name 'file1.txt' 2> errors.txt
  866  cat errors.txt 
  867  ll
  868  ls errors.txt 
  869  ll errors.txt 
  870  source .bashrc 
  871  ll errors.txt 
  872  ls -lah errors.txt
# It includes the executed commands and the history number associated to them

history | less

# To execute one of the previous commands use !HISTORY_NUMBER
!868

# To execute the last command use these shortcuts
!-1
!!

# Up & Down arrow keys can be used to scroll through history

# To execute the last "command" command - cat for example
!cat
  • The configuration options of the history are located in the .bashrc file

Command Substitution

  • Redirecting doesn't always work.

  • With command substitution a command can be replaced with its output before the entire command is executed by the shell.

  • Backticks `` or $() are used:


Last updated