Find files newer than x days

We had an arrant rsync run and started copying over new files from one system to another.

Although this is what we will want to do at some point, for now, we want to maintain the system as it was a few days ago.

I am looking for a script that will find files that are newer than x days.

Ultimately I want to traverse directories looking for these and delete but having the find command work is step one.

Thanx in advance

# make a file dated Jan 25 - you change it to what you need
touch -t 201101250000 dummy
find /path/to/files -newer dummy -exec ls -l  {} \;

Thanks Jim,

I tried this but it didn't find any files. I then touched a new file and put in in a subdirectory under where I stated and it didn't find it.

I then touched another file in the root of where I am starting my search and it was found using the following command.

  • first the touch command for the file I am looking for.
#touch ~/data/repository/thumb/vol1/fileone
  • now the touch for the file dated 1/10/2011
#touch -t 201101100000 ~/DATEFILE
  • now the find command that didn't work
#find ~/data/repository/ -newer ~/DATAFILE -exec ls -la {} \;

This returned all folders and files in this folder, not just the ones that were newer than ~/DATAFILE.

Additionally, I touched another file as today, and placed it on ~/data/repository and this one was also returned along with all folders in the ~/data/repository location.

Did I explain this well enough? Does this make sense?

The second one says ~/DATAFILE, the first ~/DATEFILE

My example assumed:
the file named dummy was in the current working directory

# more explicit example
find /path/to/files -newer ./dummy -type f -exec ls -la

This finds regular files: -type f

Consider following the example, if there is confusion. The example I gave you works on any POSIX-compliant UNIX.
The construction of a find query in the example above is:

[code]
find [path is required] -newer [exact path to file ] -type [one of -l -f -d] -exec [shell command required]
where:
-l = link
-d = directory
-f = regular file

Try:

find ~/data/repository/ -newer ~/DATAFILE -exec ls -lad {} \;

Or if you are not interested in Directory Files:

find ~/data/repository/ -type f -newer ~/DATAFILE -exec ls -lad {} \;
find . -name "*.dat" -mtime -2 -print |awk -F/ '{print $NF}'

Where *.dat --> you can give the file extension which you want

and -2 is 2 days.. so it will list the filenames which are modified/newer in last two days.. you can change this with your "x" value here.