What's the difference between "mv dir/* /tmp" and "find dir/* -print0 | xargs" ?
I use normally following command to move files:
Code:
mv dir/* /tmp/out/ Code:
find dir* -print0 | xargs -0 -I {} mv {} /tmp/out |
xargs is a clever and subtle little tool that takes a string of input and runs it's command ones for each input. So rather than a single mv command having to execute on a HUGE list of files, which can get too long and not be possible to run. so using xargs you only mv one file at any one time.
|
xargs breaks up arguments that would be too long into acceptable chunks. It's more efficient than using find -exec because find -exec only runs one argument at a time, while xargs runs more than one at a time by default.
Code:
-s max-chars |
Many thanks.
Quote:
|
Quote:
For the case of the mv command, you can use its "--target-directory=" option, which lets you place all of the source arguments at the end of the command line, eliminating the need for the "-I" option in xargs when invoking mv. |
Quote:
|
Quote:
|
Oh, yeah, I missed that. Then there is no benefit in command #2, it would be the same as using find -exec.
|
If you use find's -exec option with "+" as the terminator, rather than ";", it runs in xargs-like fashion. That is, it intelligently breaks the input file list up into optimal chunks. This is a relatively recent posix addition, I believe, so it should be useable on all newer platforms.
Code:
$ time find . -type f -exec file '{}' \; |
All times are GMT -5. The time now is 09:44 AM. |