Reprinted from: http://www.360doc.com/content/12/0405/13/532901_201081911.shtml Usage of xargs: xargs xargs - build and execute command lines from standard input When using the -exec option of the find command to process the matched files, the find command passes all the matched files to exec for execution. But some systems have a limit on the length of commands that can be passed to exec, so that after a few minutes of the find command running, an overflow error occurs. The error message is usually "parameter column too long" or "parameter column overflow". This is where the xargs command comes in, especially with the find command. The find command passes the matched files to the xargs command, and the xargs command gets only some of the files at a time instead of all, unlike the -exec option. This way it can process the first batch of files it gets, then the next batch, and so on. In some systems, using the -exec option will initiate a corresponding process for each matched file, instead of executing all the matched files as parameters at one time; in this way, there will be too many processes in some cases, and the system will The problem of performance degradation, and thus inefficiency; With the xargs command there is only one process. In addition, when using the xargs command, whether to obtain all parameters at one time or obtain parameters in batches, and the number of parameters obtained each time will be determined according to the options of the command and the corresponding tunable parameters in the system kernel. Let's see how the xargs command is used with the find command and give some examples. The following example finds every common file in the system, and then uses the xargs command to test which kind of file they belong to #find . -type f -print | xargs file
Find the memory information dump file (core dump) in the whole system, and save the result to the /tmp/core.log file: $ find / -name "core" -print | xargs echo "" >/tmp/core.log
The above execution is too slow, I changed it to look in the current directory #find . -name "file*" -print | xargs echo "" > /temp/core.log
Find all files in the current directory with read, write, and execute permissions for all users, and revoke the corresponding write permissions: # ls -l
Use grep to search all ordinary files for the word hostname: # find . -type f -print | xargs grep "hostname"
用grep命令在当前目录下的所有普通文件中搜索hostnames这个词: # find . -name \* -type f -print | xargs grep "hostnames"
注意,在上面的例子中, \用来取消find命令中的*在shell中的特殊含义。 find命令配合使用exec和xargs可以使用户对所匹配到的文件执行几乎所有的命令。
------------------------------------------------------------------------------------------------------------------------------------ 要用管道必须搞清楚标准输入和标准输出的概念。 |
linux post command xargs
Guess you like
Origin http://10.200.1.11:23101/article/api/json?id=326644943&siteId=291194637
Recommended
Ranking