• 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. “git merge-repo” Command Examples
  2. How To Create A SSH Banner in CentOS/RHEL Server
  3. setsebool: command not found
  4. Linux OS Service ‘kdump’
  5. gcal: Displays calendar
  6. ctrlaltdel: command not found
  7. User Unable To Edit crontab, Error: “/tmp/crontab.Lm34gsJV: Permission denied”
  8. sreport Command Examples in Linux
  9. adduser Command Examples in Linux
  10. What happens in the Background when you execute the “useradd” command under Linux

You May Also Like

Primary Sidebar

Recent Posts

  • “glab repo” Command Examples
  • “glab release” Command Examples
  • “glab pipeline” Command Examples
  • “glab mr” Command Examples

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright