Visit Jeremy's Blog.
Go Back > Forums > Enterprise Linux Forums > Linux - Enterprise
User Name
Linux - Enterprise This forum is for all items relating to using Linux in the Enterprise.


  Search this Thread
Old 05-05-2014, 03:18 PM   #1
LQ Newbie
Registered: Feb 2013
Posts: 13

Rep: Reputation: Disabled
using find and deleting a lot of data

Say we have a 1TB directory and we want to use 'find' to delete anything older than 1 day. Which command would finish quicker?

find . -type f -mtime +1 | xargs rm -f
find . -type f -mtime +1 -delete

I just learned about the '-delete' argument for "find" today. Obviously, there are ways I can test this myself, but I'm curious as to if anyone else already knows the answer. I would think that since the first example has to pipe to xargs, it would be slower. But I am not sure.
Old 05-06-2014, 02:37 AM   #2
Senior Member
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 2,154

Rep: Reputation: 746Reputation: 746Reputation: 746Reputation: 746Reputation: 746Reputation: 746Reputation: 746
From memory, piping in to xargs means that find will have to find all the files first then pipe the paths into xargs as a list that xargs has to parse and run the commands for.

It would seem rather pointless to do this if there's a switch in find that will do what you require.
1 members found this post helpful.
Old 05-06-2014, 03:26 AM   #3
LQ Guru
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 7,952

Rep: Reputation: 2232Reputation: 2232Reputation: 2232Reputation: 2232Reputation: 2232Reputation: 2232Reputation: 2232Reputation: 2232Reputation: 2232Reputation: 2232Reputation: 2232
the first version will fork several rm commands which will not occur in the second case. but xargs may execute those rm commands in the background which will allow to go further with the find command and therefore it can be faster. But it depends on the hardware too.
Old 05-15-2014, 09:40 AM   #4
Registered: Oct 2013
Distribution: RedHat
Posts: 224

Rep: Reputation: 25
Second way is more safety for strange named files (with spaces, for example)
And off course it "unlink" file(s) in same thread, not forking other processes.
Then it will less expensive for OS.
Old 05-15-2014, 10:42 AM   #5
Senior Member
Registered: Dec 2013
Distribution: Slackware
Posts: 1,982

Rep: Reputation: 490Reputation: 490Reputation: 490Reputation: 490Reputation: 490
The safest and fastest way to do it is:

find . -type f -mtime +1 -print0 | xargs -0 rm -f


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Starting and stopping rsync without loosing a lot of data bixbyr Linux - Networking 3 08-09-2011 02:32 PM
How to rewrite partition structure without deleting any data? mrcharles Debian 2 08-27-2009 10:46 AM
Deleting data from file by date? mephitic Linux - Newbie 3 09-22-2004 12:33 PM
Deleting Linux, All Partitions, Every Shred of Data! g-force Linux - Newbie 2 05-03-2004 10:04 PM
deleting data from ppp network control patrickfreen Red Hat 2 10-13-2003 10:15 PM

All times are GMT -5. The time now is 10:08 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration