Xargs and exec are the filters passed by commands. They capture the results of the previous command and pass it to the next command. Simply put:
- -Exec must be combined{}\;And {} indicates the Result \; Terminator of the previous query. This is a fixed method.
- Xargs must be combined with | to process files in batches at a faster speed.
I did a small experiment to count the Linux system, and list the files with a size of 1 K, 10 K, and K:
- Compare the file size with KB
[[email protected] ~]# time -p find / -size +100k | xargs ls -lart {} \;real 7.29user 1.31sys 6.89[[email protected] boot]# time -p find / -size +100k -exec ls -lart {} \;real 31.00user 6.06sys 20.88
- Compare the file size with 10
[[email protected] ~]# time -p find / -size +10k | xargs ls -lart {} \;real 12.43user 3.96sys 8.99[[email protected] ~]# time -p find / -size +10k -exec ls -lart {} \;real 105.14user 20.38sys 67.65
- Comparison of 1 kb File Size
[[email protected] ~]# time -p find / -size +1k | xargs ls -lart {} \;real 28.62user 5.72sys 24.01[[email protected] ~]# time -p find / -size +1k -exec ls -lart {} \;real 703.89user 129.08sys 456.97
Note:
- When there are few files, the execution efficiency of the two is several times different.
- When there are many files, the execution efficiency of the two is dozens of times different.
Xargs and EXEC command execution efficiency