Xargs and exec command execution efficiency
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
[root@linux ~]# time -p find / -size +100k | xargs ls -lart {} \;real 7.29user 1.31sys 6.89[root@nas2ds1 boot]# time -p find / -size +100k -exec ls -lart {} \;real 31.00user 6.06sys 20.88
Compare the file size with 10
[root@linux ~]# time -p find / -size +10k | xargs ls -lart {} \;real 12.43user 3.96sys 8.99[root@linux ~]# time -p find / -size +10k -exec ls -lart {} \;real 105.14user 20.38sys 67.65
Comparison of 1 kb File Size
[root@linux ~]# time -p find / -size +1k | xargs ls -lart {} \;real 28.62user 5.72sys 24.01[root@linux ~]# 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.