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, 04: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, 03:37 AM   #2
Senior Member
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 2,574

Rep: Reputation: 929Reputation: 929Reputation: 929Reputation: 929Reputation: 929Reputation: 929Reputation: 929Reputation: 929
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, 04:26 AM   #3
LQ Guru
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 9,892

Rep: Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921
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, 10:40 AM   #4
Registered: Oct 2013
Distribution: RedHat CentOS Fedora SuSE
Posts: 287

Rep: Reputation: 41
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, 11:42 AM   #5
Senior Member
Registered: Dec 2013
Distribution: Slackware
Posts: 1,982

Rep: Reputation: 491Reputation: 491Reputation: 491Reputation: 491Reputation: 491
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 03:32 PM
How to rewrite partition structure without deleting any data? mrcharles Debian 2 08-27-2009 11:46 AM
Deleting data from file by date? mephitic Linux - Newbie 3 09-22-2004 01:33 PM
Deleting Linux, All Partitions, Every Shred of Data! g-force Linux - Newbie 2 05-03-2004 11:04 PM
deleting data from ppp network control patrickfreen Red Hat 2 10-13-2003 11:15 PM > Forums > Enterprise Linux Forums > Linux - Enterprise

All times are GMT -5. The time now is 08:01 PM.

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