• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

CentOS / RHEL : How to get the date and time of executed command in the history command output

by admin

The default history command output is always sorted by date unless there are any changes made to the configuration. The output is not in date order because session writes their history at different times. History file is written when the session gets over. Follow the steps given below to the date of execution in the history command output.

The default output of history command is as shown below without the date and time details:

  195  ls
  196  uname -a
  197  cat /etc/redhat-release

Getting date and time of executed command in the history command output

1. Edit file /etc/bashrc and add the below entry. Make sure to have the space after %T.

# vi /etc/bashrc
export HISTTIMEFORMAT='%F %T  '

2. Login in to the system.

# su - [username]

3. Check if variable has been exported.

# echo $HISTTIMEFORMAT

4. Type history command and check if time is getting displayed.

# history

5. To have output sorted according to date run on use the sort command along with the history command.

# history | sort -n
  195  2017-09-11 10:34:42 ls
  196  2017-09-11 10:34:43 uname -a
  197  2017-09-11 10:34:48 cat /etc/redhat-release 
Solaris : How to include date and timestamp in bash shell command history
CentOS / RHEL : How to disable BASH shell history
UNIX / Linux : Examples of bash history command to repeat last commands

Filed Under: Linux

Some more articles you might also be interested in …

  1. husky Command Examples
  2. arecord Command Examples in Linux
  3. larasail Command Examples in Linux
  4. rsync Command Examples in Linux
  5. atoum: A simple, modern and intuitive unit testing framework for PHP (Command Examples)
  6. “uname” Command Examples to Check UNIX/Linux Version
  7. kscreen-console Command Examples in Linux
  8. How to uninstall speedtest-cli package from Ubuntu
  9. sed Command Examples in Linux
  10. clementine: A modern music player and library organizer

You May Also Like

Primary Sidebar

Recent Posts

  • Vanilla OS 2 Released: A New Era for Linux Enthusiasts
  • mk Command Examples
  • mixxx Command Examples
  • mix Command Examples

© 2025 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright