Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shell script to find files older than 1st Jan 2010

Tags:

linux

shell

I'm looking for a script that find all files older than 1st Jan 2010. The following isn't working for me -

date-of-my-file = $(date -r /my-file +%F)
if [ $date-of-my-file -nt "2010-01-01" ]
then
    echo "Yes"
else
    echo "No"
fi

Any help will be appreciated. P.S: touch command is not working on my box with deprecated Linux.

like image 976
fixxxer Avatar asked Dec 07 '10 15:12

fixxxer


2 Answers

Here's a one-liner:

find <dir> -not -newermt 2010-01-01

This finds all files modified before the specified date. Do a man find and look at the options for -newerXY if you want to use something besides modified date.

like image 155
davidp Avatar answered Sep 30 '22 15:09

davidp


you need to use shell commands find with newer option.

it works like: you create a file with timestamp 1.1.2010 and then compare all files with this timestamp

touch -t 01010000 /tmp/timestamp<br>
find ~ -newer /tmp/timestamp
like image 26
RusAlex Avatar answered Sep 30 '22 15:09

RusAlex