Linux: How to use History command on Linux


In Linux, the history command is used to display the history of commands executed at the current user. With the history command we will see what has been done before on the system

How to use

Enter # history

  • Another way to check the command is by viewing the history by file
  • By default, the command history will be written to ~/.bash_history, this file is located in $HISTFILE, for checking

# User roor history file location

[root@server1 ~]# echo $HISTFILE

# User history file location

[root@server1 ~]# su – duhu
[duonghuy@server1 ~]$ echo $HISTFILE

  • Command to search for statements used in the past

# history | grep [command]

  • Normally the using statement will be logged when logged out, so if your SSH session has timed out, you won’t have previous history when you log back in. You can force the current history to be written to the ~.bash_history user history file with the -w option

# history -w

  • Delete the history file with the command

# history -c

  • Delete specific command line

# history -d [n_cmd]

  • Change the format of the history output history

$ HISTTIMEFORMAT="%d/%m/%y %T "


  • %d – Date
  • %m – Month
  • %y – Year
  • %T – Time
  • / : can be changed with other characters, or spaces depending on the user’s display.
  • Ignore specific commands written to history

# export HISTIGNORE="cd"

  • Increase or decrease history storage size

By default, we can store 1000 statements to increase storage capacity as follows

[duhu@server1 ~]$ echo $HISTSIZE
[duhu@server1 ~]$ HISTSIZE=10000
[duhu@server1 ~]$ echo $HISTSIZE

To increase storage capacity up to 10000 statements

Be the first to comment

Leave a Reply

Your email address will not be published.


This site uses Akismet to reduce spam. Learn how your comment data is processed.