Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

deleteing files

Status
Not open for further replies.

zaq67

Programmer
Sep 28, 2000
3
US
Hello,
I'm trying to find files then pipe that into a command that would delete the listed files.
find ./ -atime +3. What would be a good way to delete the files without having to pipe the output to file then deleting the files.

thanks,
ziad [sig][/sig]
 
there's a delete example on the find manpage actually -- but *do* go careful please <smile> [sig]<p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>Making mistakes, so you don't have to. &lt;grin&gt;[/sig]
 
find ./ -atime +3 -exec rm -i {} \;
will find the files, and execute rm interactively, you could leave the argument off, but that's more risky.:) [sig]<p>Jon Zimmer<br><a href=mailto:b0rg@pcgeek.net>b0rg@pcgeek.net</a><br><a href= Aetea Information Technology</a><br>The software required `Windows 95 or better', so I installed Linux.<br>
[/sig]
 
You can try [tt]find / -atime +3 -type f -print | xargs -p rm[/tt], resulting in a execution of rm command for many files, not for each and every file.

I hope it works... [sig][/sig]
 
Elgis -- If I read that right it would delete every file on the system older than three days, is that correct? [sig]<p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>Making mistakes, so you don't have to. &lt;grin&gt;[/sig]
 
Ziad,

speaking from experience, it is always a good idea to test any advice before you use it.
Try running the find without rm to see what comes out of the search.
Also, when you are bulk deleting it is always a good idea to backup first. [sig]<p>Ged Jones<br><a href=mailto:gedejones@hotmail.com>gedejones@hotmail.com</a><br><a href= > </a><br>Top man[/sig]
 
Yep... try then
[tt]
find / -atime +3 -ls
[tt]

That will long list the found files and then try the previous commands! [sig][/sig]
 
And the [tt]xargs -p rm[/tt] will try to remove the (many) selected files, but it will ask before running rm![/tt]

I hope it works... [sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top