Find parameter exec, pipe character |, Xargs difference

Source: Internet
Author: User

1. All three commands can be used to make the preceding output a subsequent input.

2. They have different processing methods for the previous output.

Find. -name "*.sh"-exec cat {} \;

Find. -name "*.sh" |cat

Find. -name "*.sh" |xargs Cat

Example one:

[email protected] temp]# cat ex.sh a.txtb.txtc.txtd.txt5. Txt[[email protected] temp]# find.-name"ex.sh"-exec Cat {} \;a.txtb.txtc.txtd.txt5. Txt[[email protected] temp]# find.-name"ex.sh"|Cat./Ex.sh[[email protected] temp]# find.-name"ex.sh"|Xargs cata.txtb.txtc.txtd.txt5. Txt[[email protected] temp]#

Example two:

[[email protected] django]# find. -name"*.py"./siteone/blog/models.py./siteone/blog/__init__.py./siteone/blog/migrations/__init__.py./siteone/blog/tests.py./siteone/blog/views.py./siteone/blog/admin.py./siteone/siteone/urls.py./siteone/siteone/__init__.py./siteone/siteone/settings.py./siteone/siteone/wsgi.py./siteone/Manage.py[[email protected] django]# find.-name"*.py"-exec echo {} \;./siteone/blog/models.py./siteone/blog/__init__.py./siteone/blog/migrations/__init__.py./siteone/blog/tests.py./siteone/blog/views.py./siteone/blog/admin.py./siteone/siteone/urls.py./siteone/siteone/__init__.py./siteone/siteone/settings.py./siteone/siteone/wsgi.py./siteone/Manage.py[[email protected] django]# find.-name"*.py"|echo [[email protected] django]# find.-name"*.py"|Xargs Echo./siteone/blog/models.py./siteone/blog/__init__.py./siteone/blog/migrations/__init__.py./siteone/blog/tests.py. /siteone/blog/views.py./siteone/blog/admin.py./siteone/siteone/urls.py./siteone/siteone/__init__.py./siteone/ siteone/settings.py./siteone/siteone/wsgi.py./siteone/Manage.py[[email protected] django]#

Summarize:

EXEC executes a command on each of the files found by find.

Xargs is the argument that divides all the found filenames into one parameter and passes them to the command

A pipe symbol that is not Xargs is the standard output of the preceding standard, which is the normal input for the following command

The pipe character with Xargs is the parameter of the previous standard output, as the following command

Find parameter exec, pipe character |, Xargs difference

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.