It seems you are looking for this:
stat -c %y $filename
Or this:
date -r $filename
Or this (most portable):
fn=$filename perl -e 'print scalar localtime((stat("$ENV{fn}"))[9])'
On the other hand, stat -c %y
was already in your post, and you wrote:
Everything works (I think) except it shows more than just the date. What command would I use to just display the date of last modification?
Which makes me think that perhaps you want only the date part? One (lazy) solution for that is using shell commands like cut
, awk
, sed
to extract just what you need, for example:
$ stat -c %y sample.txt
2013-10-12 09:24:08.096820646 -0700
$ stat -c %y sample.txt | cut -f1 -d' '
2013-10-12
A better solution is to generate dates in the desired format, but that depends on the command you used. For example stat
cannot do this, but date
and perl
can, for example:
date +%Y-%m-%d -r $filename