1

I would like to be able to provide last modified timestamps to my Jekyll posts and pages using a shell script. The problem is that I do not know how to automatically generate an acceptable timestamp. The closest I have come to acceptable timestamp is using this command:

stat <FILE> | sed -n -e 's/Modify:\s//p'

which returns for my glossary.md file:

2016-02-12 09:37:55.393936224 +1000

this is almost the format I want. The only problem is I would like to remove the decimal .393936224 from it. I thought I could manage this myself using sed but all my attempts have failed. Most of my attempts involved writing this output to a text file and then using sed on this text file to remove the decimal. I would prefer any answer you give to not write the output of this to a text file, although I would like the output of your solution to be writable to a variable. e.g., if the variable is L:

L=$(stat <FILE> | sed -n -e 's/Modify:\s//p' | sed ...)

where | sed ... can be replaced with whatever your solution to this problem is.

2

date (at least in the GNU implementation common today) can take the modification time of a file directly:

> date -r ~/.bashrc +'%Y-%m-%d %H:%M:%S %z'
2015-11-10 18:50:49 +0100

(or whatever format you desire)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.