# Find files newer than x days

**URL:** <https://community.unix.com/t/find-files-newer-than-x-days/281743>\
**Category:** UNIX for Dummies Questions & Answers\
**Created:** [January 31, 2011, 11:01am UTC](https://community.unix.com/t/find-files-newer-than-x-days/281743 "2011-01-31T11:01:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Leyva62](https://community.unix.com/letter_avatar/leyva62/32/5_5575768a8748004e209b776fc1b2916d.png) [@Leyva62](https://community.unix.com/u/Leyva62)\
**Post date:** [January 31, 2011, 11:01am UTC](https://community.unix.com/t/find-files-newer-than-x-days/281743/1 "2011-01-31T11:01:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jim\_mcnamara](https://community.unix.com/letter_avatar/jim_mcnamara/32/5_5575768a8748004e209b776fc1b2916d.png) [@jim\_mcnamara](https://community.unix.com/u/jim_mcnamara)\
**Post date:** [January 31, 2011, 1:05pm UTC](https://community.unix.com/t/find-files-newer-than-x-days/281743/2 "2011-01-31T13:05:38Z")

</div>

```nohighlight
# 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 {} \;

```

---

<div class="post-metadata">

**Author:** ![Leyva62](https://community.unix.com/letter_avatar/leyva62/32/5_5575768a8748004e209b776fc1b2916d.png) [@Leyva62](https://community.unix.com/u/Leyva62)\
**Post date:** [January 31, 2011, 1:42pm UTC](https://community.unix.com/t/find-files-newer-than-x-days/281743/3 "2011-01-31T13:42:39Z")

</div>

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.

```nohighlight
#touch ~/data/repository/thumb/vol1/fileone

```

- now the touch for the file dated 1/10/2011

```nohighlight
#touch -t 201101100000 ~/DATEFILE

```

- now the find command that didn't work

```nohighlight
#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?

---

<div class="post-metadata">

**Author:** ![jim\_mcnamara](https://community.unix.com/letter_avatar/jim_mcnamara/32/5_5575768a8748004e209b776fc1b2916d.png) [@jim\_mcnamara](https://community.unix.com/u/jim_mcnamara)\
**Post date:** [January 31, 2011, 3:57pm UTC](https://community.unix.com/t/find-files-newer-than-x-days/281743/4 "2011-01-31T15:57:40Z")

</div>

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

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

```nohighlight
# 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

---

<div class="post-metadata">

**Author:** ![methyl](https://community.unix.com/letter_avatar/methyl/32/5_5575768a8748004e209b776fc1b2916d.png) [@methyl](https://community.unix.com/u/methyl)\
**Post date:** [January 31, 2011, 8:45pm UTC](https://community.unix.com/t/find-files-newer-than-x-days/281743/5 "2011-01-31T20:45:01Z")

</div>

> [@](#):
>
> find ~/data/repository/ -newer ~/DATAFILE -exec ls -la {} \;

Try:

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

```

Or if you are not interested in Directory Files:

```plaintext
find ~/data/repository/ -type f -newer ~/DATAFILE -exec ls -lad {} \;

```

---

<div class="post-metadata">

**Author:** ![ezhilan2307](https://community.unix.com/letter_avatar/ezhilan2307/32/5_5575768a8748004e209b776fc1b2916d.png) [@ezhilan2307](https://community.unix.com/u/ezhilan2307)\
**Post date:** [February 1, 2011, 2:15am UTC](https://community.unix.com/t/find-files-newer-than-x-days/281743/6 "2011-02-01T02:15:40Z")

</div>

```nohighlight
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.
