Usually the date +%d
gives the output 08
for the current date, 08/10/2017. But when I do the ls -lrt
on a path, the date format is like Oct 8 15:03
, so, how do I get the files of the current date?
I'm using the command
ls -lrt XYZ.LOG* |grep "$(date +'%b %d')" |awk '{print $9}'
but it's not giving me the file of today's date (08/10/2017) although it gives me correct output for the dates 10 - 31st of any month.
find
, you can skip the temp file and use time strings directly with the-newerXY
test e.g.find . -type f -newermt yesterday
– steeldriver Oct 08 '17 at 14:19yesterday
would refer to "this time yesterday" which may cause files modified before midnight to be returned. – Kusalananda Oct 08 '17 at 14:230
works though... – Kusalananda Oct 08 '17 at 14:29$ touch -d "$(date +%FT00:00:00)" /tmp/midnight touch: illegal option -- d usage: touch [-amc] [-t [[CC]YY]MMDDhhmm[.SS] | -r ref_file] file ...
– ashish_k Oct 08 '17 at 14:50-d
flag is a POSIX standard flag. Oh well, change that line totouch -t "$(date +%Y%m%d0000)" /tmp/midnight
. – Kusalananda Oct 08 '17 at 14:55