0

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.

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.