The bash history command on Linux systems helps with remembering commands you\u2019ve previously run and repeating those commands without having to retype them.\nYou could decide, however, that you\u2019d be just as happy to forget that you referenced a dozen man pages, listed your files every 10 minutes or viewed previously run commands by typing \u201chistory\u201d. In this post, we\u2019re going to look at how you can get the history command to remember just what you want it to remember and forget commands that are likely to be of little "historic value".\nViewing your command history\nTo view previously run commands, you simply type \u201chistory\u201d. You\u2019ll probably see a long list of commands. The number of commands remembered depends on an environment variable called $HISTSIZE\u00a0that is set up in your ~\/.bashrc file, but there\u2019s nothing stopping you from changing this setting if you want to save more or fewer commands.\nTo view history, use the history command:\n$ history\n209 uname -v\n210 date\n211 man chage\n...\n\nTo see the maximum number of commands that will be displayed:\n$ echo $HISTSIZE\n500\n\nYou can change $HISTSIZE and make the change permanent by running commands like these:\n$ export HISTSIZE=1000\n$ echo \u201cHISTSIZE=1000\u201d >> ~\/.bashrc\n\nThere\u2019s also a difference between how much history is preserved for you and how much is displayed when you type \u201chistory\u201d. The $HISTSIZE variable controls how much history is displayed while the $HISTFILESIZE\u00a0variable controls how many commands are retained in your .bash_history file.\n$ echo $HISTSIZE\n1000\n$ echo $HISTFILESIZE\n2000\n\nYou can verify the second variable by counting the lines in your history file:\n$ wc -l .bash_history\n2000 .bash_history\n\nOne thing to keep in mind is that commands that you enter during a login session aren\u2019t added to your .bash_history file until you log off, even though they show up in the history command output right away.\nUsing history\nThere are three ways to reissue commands that you find in your history. The simplest way, especially if the command you want to reuse was run recently, is often to type a ! followed by enough of the first letters in the command's name to uniquely identify it.\n$ !u\nuname -v\n#37-Ubuntu SMP Thu Mar 26 20:41:27 UTC 2020\n\nAnother easy way to repeat a command is to simply press your up-arrow key until the command is displayed and then press enter.\nAlternately, if you run the history command and see the command you want to rerun listed, you can type an ! followed by the sequence number shown to the left of the command.\n$ !209\nuname -v\n#37-Ubuntu SMP Thu Mar 26 20:41:27 UTC 2020\n\nHiding history\nIf you want to stop recording commands for some period of time, you can use this command:\n$ set +o history\n\nCommands will not show up when you type "history" nor will they be added to your .bash_history file when you exit the session by logging off or exiting the terminal.\nTo reverse this setting, use set -o history. To make it permanent, you can add it to your .bashrc file, though failing to make use of command history altogether is generally not a good idea.\n$ echo 'set +o history' >> ~\/.bashrc\n\nTo temporarily clear history, so that only commands that you enter afterwards show up when you type "history", use the history -c (clear) command:\n$ history | tail -3\n209 uname -v\n210 date\n211 man chage\n$ history -c\n$ history\n1 history\n\nNOTE: The commands entered after typing "history -c" will not be added to your .bash_history file.\nControlling history\nThe command history settings on many systems will default to including one called $HISTCONTROL that ensures that, even if you run the same command seven times in a row, it will only be remembered once. It also ensures that commands that you type after first entering one or more blanks will be omitted from your command history.\n$ grep HISTCONTROL .bashrc\nHISTCONTROL=ignoreboth\n\nThe "ignoreboth" means "ignore both duplicate commands and command starting with blanks". For example, if you type these commands:\n$ echo try this\n$ date\n$ date\n$ date\n$\u00a0 \u00a0pwd\n$ history\n\nyour history command should report something like this:\n$ history\n$ echo try this\n$ date\n$ history\n\nNotice that the sequential date commands were reduced to one and the indented command was omitted.\nOverlooking history\nTo ignore certain commands so that they never show up when you type "history" and are never added to your .bash_history file, use the $HISTIGNORE setting. For example:\n$ export HISTIGNORE=\u201dhistory:cd:exit:ls:pwd:man\u201d\n\nThis setting will cause all history, cd, exit, ls, pwd and man commands to be omitted from your history output and your .bash_history file.\nIf you want to make this setting permanent, you have to add it to your .bashrc file.\n$ echo 'HISTIGNORE="history:cd:exit:ls:pwd:man"' >> .bashrc\n\nThis setting just means that when you look back through previously run commands, the list won\u2019t be cluttered by commands that you're unlikely to be looking for when you are looking through your command history.\nRemembering, ignoring and forgetting the past\nCommand history is useful because it helps you remember what commands you\u2019ve recently used and reminds you about changes you\u2019ve recently made. It also makes it easier to rerun commands, especially those with a string of arguments that you don't necessarily want to recreate. Tailoring your history settings can make your use of command history a little easier and more efficient.