Find: xargs -vs- exec
‘-exec’ using trailing ‘\’
[root@monk ~]# tar -cvf test.tar install.log
install.log
[root@monk ~]# time find /tmp/conf-2-xp -name *.xad -exec tar –append –file=/root/test.tar {} +;
find: /tmp/conf-2-xp/9a2f6257887d6e51f58ce2/amd64: Permission denied
find: /tmp/conf-2-xp/9a2f6257887d6e51f58ce2/i386: Permission denied
find: /tmp/conf-2-xp/System Volume Information: Permission denied
tar: Removing leading `/’ from member names
real 0m15.239s
user 0m0.464s
sys 0m2.628s
[root@monk ~]# du -h test.tar
310M test.tar
[root@monk ~]# rm -f test.tar
*delete fiel and recreate since we are appending and comparing file size after each run.
‘-exec’ using trailing ‘+’
[root@monk ~]# tar -cvf test.tar install.log
install.log
[root@monk ~]# time find /tmp/conf-2-xp -name *.xad -exec tar –append –file=/root/test.tar {} \;
find: /tmp/conf-2-xp/9a2f6257887d6e51f58ce2/amd64: Permission denied
find: /tmp/conf-2-xp/9a2f6257887d6e51f58ce2/i386: Permission denied
…
real 0m39.015s
user 0m2.739s
sys 0m21.893s
[root@monk ~]# du -h test.tar
310M test.tar
Using xargs.
*use -print0 option to prevent whitespace issue. ‘xargs -0′ passes first argument.
[root@monk ~]# rm test.tar
rm: remove regular file `test.tar’? yes
[root@monk ~]# tar -cvf test.tar install.log
install.log
[root@monk ~]# time find /tmp/conf-2-xp -name ‘*.xad’ -print0 | xargs -0 tar –append –file=/root/test.tar;
find: /tmp/conf-2-xp/9a2f6257887d6e51f58ce2/amd64: Permission denied
find: /tmp/conf-2-xp/9a2f6257887d6e51f58ce2/i386: Permission denied
find: /tmp/conf-2-xp/System Volume Information: Permission denied
tar: Removing leading `/’ from member names
real 0m15.073s
user 0m0.446s
sys 0m2.774s
[root@monk ~]# du -h test.tar
310M test.tar
Result: Using ‘+’ is two times faster than using ‘\’. -exec and xargs are about the same speed, when using ‘+’ for -exec.