Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Script to delete huge sparsebundle images' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Script to delete huge sparsebundle images
Authored by: fracai on Jul 19, '12 08:16:35AM
I'm not sure what the problem with rm -rf /path/to/folder/ could have been, I've never had a problem with recursively removing large directories. rm -rf /path/to/folder/*? Sure, there's a limit to how many arguments can be passed on the command line. But, that's where xargs comes in.

For example:
find /path/to/folder -print0 | xargs -0 rm -f

That's it. The -print0 separates the found items with a null character so you don't have to worry about escaping characters. xargs -0 recognizes the null separation and passes the listed arguments to whatever command follows next. Plus, xargs is smart enough to not send more arguments than is allowed to the command to be executed.

But, there's an even easier option:
find /path/to/folder -print -delete

The -print is optional, but allows you to see the files as they are deleted. I'm sure it would delete faster if you omit the printing.

Add a sudo as required. Note, that the first example uses a pipe, so you'd need to use sudo before the xargs command as well.

And of course, remember that you're deleting files here, be careful.
---
i am jack's amusing sig file


[ Reply to This | # ]
Script to delete huge sparsebundle images
Authored by: richard2 on Jul 19, '12 10:04:34AM

You can simplify

find Path -print0 | xargs -0 Command

to

find Path -exec Command {} +

find's documentation describes this syntax as follows:

-exec utility [argument ] {} +
Same as -exec, except that "{}" is replaced with as many pathnames as possible for each invocation of utility. This behaviour is similar to that of xargs(1).

Edited on Jul 19, '12 10:11:53AM by richard2


[ Reply to This | # ]
Script to delete huge sparsebundle images
Authored by: fracai on Jul 19, '12 10:16:34AM

Yeah, I've always preferred piping to xargs though. I think it's the requirement to use brackets to insert the arguments and the cryptic, required terminator '+' or ';'.

And if you need to have arguments after the found files, you can always use the -I (or -J?) flags to specify an insertion character.

To each their own.

---
i am jack's amusing sig file
Edited on Jul 19, '12 10:18:50AM by fracai



[ Reply to This | # ]
Script to delete huge sparsebundle images
Authored by: wjv on Jul 26, '12 05:34:59AM
xargs is preferable as it would result in vastly fewer invocations of Command.

[ Reply to This | # ]