Understanding and simple application of Xargs

Source: Internet
Author: User


When we use the Find command to find some files, because find passes the found file to the command specified later, all eligible files are found to be passed to the following command at one time, but some systems have a limit on the length of the command that can be passed to exec. This will cause an overflow error after the find command runs for a few minutes. The error message is usually "parameter column too Long" or "parameter column overflow". This is where the Xargs command is used, especially with the Find command. the format used with the Find command is as follows:

Find | Xargs COMMAND

XARGS


. Xargs-Construct the parameter list from a standard input or pipe and run the command

Xargs is a common command for UNIX and UNIX-like operating systems. It does this by converting the argument list to small pieces to pass to other commands to avoid the problem of too long a parameter list.

Xargs is a very powerful command that can take the output of one command as a parameter to another command.

This Xargs command performs an interesting function. It accepts input from a standard input or pipe and converts the input into a list of parameters for a particular command.


Because of these features of the Xargs command, when we use the Find command to find some files and pass the lookup results to the command specified later, if you are concerned that the command specified later cannot accept too many arguments and cause the command to get an error, you can use the Xargs command to accept the find The output of the command and as a parameter list of the Xargs command itself;

such as the following command:

[[email protected] ~]# mkdir-p-v playground/dir-{00{1..99},0{10..99},100}

[[email protected] ~]# 1014 Touch Playground/dir-{00{1..99},0{10..99},100}/file-{a-z}

Create 100 subdirectories, create 26 empty files under each sub-directory;

[Email protected] ~]# find/root/playground-type f-name ' file-a '

Using the Find command to locate the file-a file, this command produces a longer output (190 rows), in which case we can use the Xargs command to accept the output of the find command through a pipeline, and take the output of the Find command as a parameter to a command, such as Ls-l Command:

[Email protected] ~]# find/root/playground-type f-name ' file-a ' | Xargs ls-l


Effect and

[[email protected] ~]find/root/playground-type f-name ' file-a '-exec ls-l {} \;

command as well as effective to avoid the number of arguments too many causes the command overflow error situation ;


Note: Here are just a few simple ways to use the Xargs command without parameters, refer to other blogs or wait for a blog update for xargs with parameters.


Understanding and simple application of Xargs

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.