Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I use the command "history" can show all command that I used perviously , but if I want to know when ( what time ) I used this command , can advise what can i do ? thx
" If the shell variable HISTTIMEFORMAT is set and not null, it is used as a format string for
strftime(3) to display the time stamp associated with each displayed history entry.
No intervening blank is printed between the formatted time stamp and the history line.
"
Hmmm, the man page mentions this briefly, but it looks like you would need to do some programming to perhaps build a utility to utilize this. Searching on google I could not find anything, but in the man page I see this:
time_t history_get_time (HIST_ENTRY *)
Return the time stamp associated with the history entry passed as the
argument
Again, I have not figured out how to use that option, but it seems like you have to use it with some custom code. Good luck, man.
I'd love to figure out how you get this functionality.
If the shell variable HISTTIMEFORMAT is set and not null, it is used as a format string for strftime(3)
This tells you that HISTTIMEFORMAT is a shell variable, which is used as a format string with the rules used by the C function strftime, or if you prefer by the date command. So, you have simply to do something like
Code:
export HISTTIMEFORMAT="%Y%m%d %H:%M:%S "
put this in your ~/.bashrc to make it permanent and magically your history file will be populated by dates in the format you have chosen.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.