Real Love Starts with a Simple Message



Linux Command History with date and time - Stack Overflow Linux Command History with date and time.

I wants to check on my linux system when which command was fired - at which date and time.

I fired commands like this: It shows me the last 50 commands Linux Command History with date and time.

Click here for Find a date in history


I wants to check on my linux system when which command was fired - at which date and time.

I fired commands like this: It shows me the last 50 commands history, but not with date and time at which it was fired.

Does any one knows how to do it?

Setting HISTTIMEFORMAT changes format for future commands, so that timestamp will be saved for them.

Timestamps for commands fired before setting HISTTIMEFORMAT were not saved in histfile, so there's no way to show them.

8 Answers 8.

It shows today's date and time for all previously executed commands which is wrong, is there any way I can get the correct date and time when previous commands were executed?

You're going to want this in all of your interactive shells, not just login shells.

As such, you want to set HISTTIMEFORMAT in .bashrc rather than in .bashprofile.

You can adjust the format to your liking, of course.

This does not show date and time of command when it was fired.

Lets say command was fired yesterday but if I write as you suggested it will show todays date.

Which I do not want.

RJ07: This won't work on commands executed in the past, since no timestamp was saved for them.

However, if you add this to your bash.src, the timestamps will be saved for all future bash inputs.

OK, this only works for THE FUTURE.

As Rushvi says it doesn't update past histories.

still ok though.

In case you are using zsh you can use for example the -E or -i switch: If you do a man zshoptions or man zshbuiltins you can find out more information about these switches as well as other info related to history: This answer was best suited.

I have zsh , so it seemed redundant to explicitly set formats in .zshrc , if we can do the same thing with a predefined option.

It depends on the shell (and its configuration) in standard bash only the command is stored without the date and time (check .bashhistory if there is any timestamp there).

To have bash store the timestamp you need to set HISTTIMEFORMAT before executing the commands, e.g.

in .bashrc or .bashprofile .

This will cause bash to store the timestamps in .bashhistory (see the entries starting with ).

For any commands typed prior to this, it will not help since they will just get a default time of when you turned history on, but it will log the time of any further commands after this.

If you want it to log history for permanent, you should put the following line in your .bashrc.

It depends on which shell you are using.

For GNU Bash, changing the HISTTIMEFORMAT variable will help.

This nixCraft article explains how to set that variable permanently, but uses an ambiguous date format.

For ISO 8601, use: On macOS without editing any rc files: Solved with two simple commands: The date and time associated with each history entry can be written to the history file, marked with the history comment character by setting the HISTTIMEFORMAT variable.

The Overflow Blog.

Linked.

Related.

Hot Network Questions.

Subscribe to RSS.

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

Site design logo 2024 Stack Exchange Inc, user contributions licensed under CC BY-SA .

rev 2024.7.1.11758.

Linux Command History with date and time - Stack Overflow Linux Command History with date and time.

I wants to check on my linux system when which command was fired - at which date and time.

I fired commands like this: It shows me the last 50 commands Linux Command History with date and time.

I wants to check on my linux system when which command was fired - at which date and time.

I fired commands like this: It shows me the last 50 commands history, but not with date and time at which it was fired.

Does any one knows how to do it?

Setting HISTTIMEFORMAT changes format for future commands, so that timestamp will be saved for them.

Timestamps for commands fired before setting HISTTIMEFORMAT were not saved in histfile, so there's no way to show them.

8 Answers 8.

Keywords: find a date in history