1829553 Members
2036 Online
109992 Solutions
New Discussion

find

 
SOLVED
Go to solution
Tarek_1
Frequent Advisor

find

Hi
i want to delete from a directory all files of two day before. The issue is that files does not contain the date inside the name, so how to find which files to del?
I tried with
find . -atime +1 (to see files of yesterday) but this doesn't work.
Any tip?
Thanks
4 REPLIES 4
Goran Koruga
Honored Contributor

Re: find

Hi.

Try something like this :

find ~ -daystart -type f -mtime -2

HTH,
Goran
Ramkumar Devanathan
Honored Contributor

Re: find

Why doesn't the find command work?

can you paste out the output if it is short, or attach the output file if it is quite long?

- ramd.
HPE Software Rocks!
John Poff
Honored Contributor
Solution

Re: find

Hi,

I used the 'touch' command with the date option to create several files with dates from the last few days, and then I used the find command with -atime to get files accessed from two days or older. Here is what I got:


$ ls -l
total 4
-rw-r--r-- 1 jpoff users 0 Mar 29 00:00 file1
-rw-r--r-- 1 jpoff users 0 Mar 30 00:00 file2
-rw-r--r-- 1 jpoff users 0 Mar 31 00:00 file3
-rw-r--r-- 1 jpoff users 0 Apr 1 00:00 file4
-rw-r--r-- 1 jpoff users 0 Apr 2 00:00 file5
-rw-r--r-- 1 jpoff users 0 Apr 3 00:00 file6


$ find . -atime +2
/file1
/file2
/file3

$ find . -atime +1
/file1
/file2
/file3
/file4


If that works for you, you should be able to do something like this to remove them:

find . -atime +2 -exec rm {} \;


JP
Tarek_1
Frequent Advisor

Re: find

Hi
i don't know. Yesterday that find statement didn't work, today yes. And i'm quite sure that there were files one day old.
However now it's ok. Thanks for your help.
Tarek