How do you use the history command?

Answer

history displays a numbered list of previously executed commands. history 20 shows the last 20 commands. Re-run a command by number: !42 runs command 42. !! repeats the last command (useful with sudo !! when you forgot sudo). !string runs the most recent command starting with that string. Press Ctrl+R for interactive reverse search through history. The history is stored in ~/.bash_history. history -c clears the in-memory history. HISTSIZE controls how many commands are remembered; HISTFILESIZE controls the file size.