Whenever you work with the command-line, there will be times when you’ll have to enter some commands more than once. If you’ve just entered a command that’s long and complex, you may not exactly be thrilled at the prospect of having to type it in all over again. Not to worry, though. For this, bash
and zsh
give you the ability to recall and/or edit commands that you’ve previously entered. There are a few ways to do this.
Whenever you enter a command, it gets stored in memory until you exit the shell session. The command will then get added to a file that’s specified by the HISTFILE
variable. Usually, this is the .bash_history
file on bash
, and the .histfile
file on zsh
. You’ll find these stored in each user’s home directory. To verify that, you can use the echo
command, like this:
[donnie@fedora ~]$ echo $HISTFILE
/home/donnie/.bash_history
[donnie@fedora ~]$
On zsh
, you’ll see this...