How to check History Command With Date and Time in Linux? If you want to see command history in Linux with date and time, here is how to get all command history in Linux Ubuntu.
History Command :
The history command shows the most recently used command history.
history [-c] [-d offset]
Also Read: How to Split Terminal in Ubuntu 2021
History Command Options:
- -c: remove all entries in the history list.
- -d offset: Remove the history entry at offset OFFSET.
- -a: append this session’s history lines to the history file.
- -n: read all history lines from the history file that haven’t been read already.
- -r: appends the history file’s contents to the history list.
- -w: append the current history to the history list by writing the current history to the history file.
- -p: expand each ARG’s history and present the result instead of storing it in the history list.
- -s: add the ARGs as a single entry to the history list.
Note: When we use the history command, it does not display the time at which the commands in the bash history were executed. Build a shell variable called HISTTIMEFORMAT to solve this problem and of history command with timestamp.
History Command With Date and Time in Linux
(1) Define the environment variable named HISTTIMEFORMAT and add to your ~/.bash_profile file, enter:
$ echo 'export HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bash_profile
Where, %d – Day %m – Month %y – Year %T – Time
(2) Type the below command to check whether our Environment Variable(HISTTIMEFORMAT) is defined in the bash_profile file or not.
$ nano ~/.bash_profile
(3) To load HISTTIMEFORMAT from the file into the current shell script or command prompt, use the source command:
$ source ~/.bash_profile
Now run the history command to retrieve command line history by date and time in Linux.
Also Read: Where WhatsApp Status is Stored?