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

The Geek Diary

CONCEPTS | BASICS | HOWTO

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • Linux Services
    • VCS
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
    • Data Guard
  • DevOps
    • Docker
    • Shell Scripting
  • Interview Questions
  • 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. How to Change Timezone from CST To EST in CentOS/RHEL 7 Server
  2. Linux OS Service ‘squid’
  3. How to block non-root user from creating crontab entry in Linux
  4. CentOS / RHEL : How to delete a volume group in LVM
  5. CentOS / RHEL : How to find the creation time of LVM volume
  6. How to change the default location (/var/cache/yum) of yum cache
  7. What is the purpose of .bash_profile file under User Home Directory In Linux
  8. Audit Rule Configuration not Reflected – How to troubleshoot
  9. Linux OS Service ‘scsi_reserve’
  10. How to install/remove/query/update RPM packages in Linux (Cheat Sheet)

You May Also Like

Primary Sidebar

Recent Posts

  • Oracle Database – Configuring Secure Application Roles
  • Extend rule sets by using factors in Oracle Database Vault
  • What are Command Rules in oracle Database
  • Using Rule Sets in Oracle Database Vault
  • Archives
  • Contact Us
  • Copyright

© 2021 · The Geek Diary