So, given three options...
find .... -deletefind .... | xargs rm ...find .... -exec rm ...;
..or variations thereof, which option is preferable?
I'm guessing there is no hard and fast answer, and a specific situation will dictate the best option (please name them!)
Cheers.
-
I prefer to use
find ... > file.txtreview the file extensively, then usefind ... -deleteso I know the exact same results will be deleted (passing arguments is mostly bulletproof, mostly).From Chris S -
Option 1 will avoid spawning external processes, which is useful under stressed conditions.
Option 2 will spawn a single
xargsprocess, which will spawn only as manyrmprocesses as necessary. This option is typically used with-print0and-0in order to handle filenames with spaces and/or newlines.Option 3 will spawn a
rmprocess for each file.GNU find allows a fourth option,
find .... -exec rm -r {} +, which will runrmwith as many filenames as possible in order to spawn only a limited number of them.standard : Thanks, nice explanation of each option.Brian Knoblauch : I only ever use the xargs method in practice. -
Be careful, some of them have different behavior. For example if the path has a space in it, the second option using xargs will interpret the path as multiple files and throw errors (and cause other problems).
From paulusdd
0 comments:
Post a Comment