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

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • 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. check-support-status: Command Examples in Linux
  2. How to split iso or file using ‘split’ command in Linux
  3. How to Find Filesystem Inode Utilization in Linux
  4. e4defrag Command Examples in Linux
  5. CentOS / RHEL : How to Install and Configure OpenSSH Server and Client
  6. avahi-browse Command Examples in Linux
  7. acpi Command Examples in Linux
  8. ascii Command Examples in Linux
  9. How to use wget to download file via proxy
  10. isosize Command Examples in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • qm Command Examples in Linux
  • qm wait Command Examples in Linux
  • qm start Command Examples in Linux
  • qm snapshot Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright