Find files newer than x days


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Find files newer than x days
# 1  
Old 01-31-2011
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
# 2  
Old 01-31-2011
Code:
# 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  {} \;

# 3  
Old 01-31-2011
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.
Code:
#touch ~/data/repository/thumb/vol1/fileone

- now the touch for the file dated 1/10/2011
Code:
#touch -t 201101100000 ~/DATEFILE

- now the find command that didn't work
Code:
#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?

Last edited by Yogesh Sawant; 02-01-2011 at 09:48 AM.. Reason: added code tags
This User Gave Thanks to Leyva62 For This Post:
# 4  
Old 01-31-2011
The second one says ~/DATAFILE, the first ~/DATEFILE

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

Code:
# 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

Last edited by jim mcnamara; 01-31-2011 at 05:02 PM..
# 5  
Old 01-31-2011
Quote:
find ~/data/repository/ -newer ~/DATAFILE -exec ls -la {} \;
Try:
Code:
find ~/data/repository/ -newer ~/DATAFILE -exec ls -lad {} \;

Or if you are not interested in Directory Files:
Code:
find ~/data/repository/ -type f -newer ~/DATAFILE -exec ls -lad {} \;


Last edited by methyl; 01-31-2011 at 09:47 PM.. Reason: Minor typo
# 6  
Old 02-01-2011
Try this :

Code:
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.

Last edited by Yogesh Sawant; 02-01-2011 at 09:48 AM.. Reason: added code tags
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find the sum of files created 5 days before

Hi, I want to find the sum of all the files created 5 days ago and store it in a variable. (os is HP-UX) can this be extracted from ls -l Is there any other way of getting the sum of all the files created (4 Replies)
Discussion started by: bang_dba
4 Replies

2. UNIX for Advanced & Expert Users

find files older than 30 days old

Hello, I have a script which finds files in a directory that are older than 30 days and remove them. The problem is that these files are too many and when i run this command: find * -mtime +30 | xargs rm I run this command inside the directory and it returns the error: /usr/bin/find:... (8 Replies)
Discussion started by: omonoiatis9
8 Replies

3. Shell Programming and Scripting

what is the find to command to find the files created last 30 days

what is the find to command to find the files created last 30 days (5 Replies)
Discussion started by: rajkumar_g
5 Replies

4. Shell Programming and Scripting

Find last 2 days files.

Need to cpy those files which are created or modified in last 2 days. bash$ ll -lrt total 184 drwxr-xr-x 2 ons dce 256 Oct 12 06:58 files -rw-r--r-- 1 ons dce 4313 Oct 14 06:06 cab.ksh -rw-r--r-- 1 ons dce 6 Oct 14 07:03 Code.txt... (2 Replies)
Discussion started by: saluja.deepak
2 Replies

5. UNIX for Dummies Questions & Answers

How to find files created some days before?

HI, I have 2 questions. 1> Is there any code to see files that created some day or some time before in a directory??? 2> how or where i will find the last exit status of a process?? thanks (6 Replies)
Discussion started by: jyotidas
6 Replies

6. UNIX Desktop Questions & Answers

Find files older than 10 days

What command arguments I can use in unix to list files older than 10 days in my current directory, but I don't want to list the hidden files. find . -type f -mtime +15 -print will work but, it is listing all the hidden files., which I don't want. (4 Replies)
Discussion started by: Pouchie1
4 Replies

7. Shell Programming and Scripting

How to find files older than 30 days

Dear Friends, I have two queries. 1) I want to see the list of folders which were created 29 days ago. 2) I want to see the folders in which last created file is older than 29 days. Can it be done? Thank you in advance Anushree (4 Replies)
Discussion started by: anushree.a
4 Replies

8. Shell Programming and Scripting

find files from the past 7 days

Hi All, I have a file which contains the listing of another directory: >cat list.dat -rwxr-xr-x 1 test staff 10240 Oct 02 06:53 test.txtdd -rwxrwxrwx 1 test staff 0 Oct 04 07:22 test.txx -rwxrwxrwx 1 test staff 132 Sep 16 2007 test_tt.sh... (6 Replies)
Discussion started by: deepakgang
6 Replies

9. Shell Programming and Scripting

Find files older than 20 days & not use find

I need to find files that have the ending of .out and that are older than 20 days. However, I cannot use find as I do not want to search in the directories that are underneath the directory that I am searching in. How can this be done?? Find returns files that I do not want. (2 Replies)
Discussion started by: halo98
2 Replies

10. UNIX for Dummies Questions & Answers

Find files newer than...

Is there a way to use the find command to locate files newer than a specific date? Thanks! --Alex (4 Replies)
Discussion started by: vertigo23
4 Replies
Login or Register to Ask a Question