简体   繁体   中英

Using timestamp of a particular command in bash script?

I'm trying to use the timestamps of a particular command I ran previously. Running something along the lines of history 10 | grep "keyword" 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM