LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Enterprise Linux Forums > Linux - Enterprise
User Name
Password
Linux - Enterprise This forum is for all items relating to using Linux in the Enterprise.

Notices

Reply
 
Search this Thread
Old 05-05-2014, 04:18 PM   #1
boblc123
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
or
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
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6
Posts: 1,593

Rep: Reputation: 483Reputation: 483Reputation: 483Reputation: 483Reputation: 483
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
pan64
Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 5,142

Rep: Reputation: 1363Reputation: 1363Reputation: 1363Reputation: 1363Reputation: 1363Reputation: 1363Reputation: 1363Reputation: 1363Reputation: 1363Reputation: 1363
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
voleg
Member
 
Registered: Oct 2013
Distribution: RedHat
Posts: 145

Rep: Reputation: 5
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
metaschima
Senior Member
 
Registered: Dec 2013
Distribution: Slackware
Posts: 1,519

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

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


Reply


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


All times are GMT -5. The time now is 09:06 AM.

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