I'm trying to read the number of lines in a file, and the last modification date of that file (e.g. if it was last modified Jan 18, 2013, it should output 2013-01-18
), then append the data to the given input file in the form theFile: 4 lines, modified on 2013-01-18
. I tried to store both pieces of data in their own variables before outputting with echo.
#!/bin/sh
totLines=$(wc -l < $1)
modDate=$(date -r $1)
echo $1: $totLines "lines, modified on" $modDate >> $1
Is my method of finding the last modification date correct? I was told that it is, but I can't figure out why, since I can't find any information on what date -r
does and I can't get it working in any script I try out. There's also using stat, but I can't get that working either with stat -c %y $1
where I get stat: illegal option -- c
FreeBSD
,stat -x
equal withstat
inlinux
. – PersianGulf Jan 31 '13 at 07:09