Skip to content

history Command

The history command allows you to view and edit your command history.

history output
ali@gnuadmin:~$ history
   10  ip a
   11  sudo su -
   12  sudo hostnamectl set-hostname gnuadmin
   13  exit
   16  echo gnuadm.in
   18  sudo dmesg
   19  echo $USER
   20  echo $HOME
   21  echo $SHELL
   22  echo "$SHELL shell'ini kullanan $USER kullanıcısının ev dizini: $HOME"
   23  echo "$SHELL shell'ini kullanan $USER kullanıcısının ev dizini: $HOME" > test
   30  echo $PWD
   31  echo "$PWD"
   32  echo '$PWD'
   35  history

In the Linux Bash shell, the history of commands is kept in the ~/.bash_history file by default. The commands you type are not transferred to this file instantly.

Saving Command History in Linux

You can use the history -a command to save commands from your active session to the ~/.bash_history file.

Deleting Command History in Linux

You can use the history -c command to delete the commands you wrote in the active session from the history. In order to delete the entire history, you need to clean the files where the history records are kept. If you are using the default settings, simply delete the ~/.bash_history file.

Of course, it's assumed that the shell you are using is Bash.