Xargs and EXEC command execution efficiency

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.