Saturday, July 18, 2009

How to list only today's files

Sometimes you may have difficulties in finding those files created/modified today using "find -mtime" command. What we can do is to take advantage of the "-nt" (file newer) conditional expression. By creating a file at exactly today at 00:00, we can use that to compare.
today="/tmp/today.$$"
touch -t `date '+%Y%m%d0000'` $today
for i in `find . -type f`
do
    if [ $i -nt $today ]; then
        echo $i
    fi
done
rm -f $today

BTW, "-nt" available only in Korn and Bash shell.

Labels: ,

0 Comments:

Post a Comment

<< Home