Reputation: 411
I'm trying to use the timestamps of a particular command I ran previously. Running something along the lines of history 10 | grep "keyword"
gives me the output in the command line (my history preferences are set up to include a timestamps), but I can't actually figure out how to utilize this information in a script.
Is there any way to use this or another way to get the timestamps from a particular command? I'm trying to determine the last time a command
was run, and if it was longer than a specific amount of time, run it again.
Upvotes: 0
Views: 70
Reputation: 3967
If you have used the timestamp format in history as
export HISTTIMEFORMAT="%F %T "
then you can use this command
history | grep ls | grep -v grep | tail -1 | awk '{print $2,$3;}'
NOTE: I am searching for command ls and i am printing the timestamp of the command ls when it was last used
Upvotes: 1