- 论坛徽章:
- 0
|
xargs - build and execute command lines from standard input
This manual page documents the GNU version of xargs. xargs reads items from
the standard input, delimited by blanks (which can be protected with double
or single quotes or a backslash) or newlines, and executes the command
(default is /bin/echo) one or more times with any initial-arguments followed
by items read from standard input. Blank lines on the standard input are
ignored.
默认情况下:xargs是忽略了空格和线这些文件名。让查找跟准确。
Because Unix filenames can contain blanks and newlines, this default
behaviour is often problematic; filenames containing blanks and/or newlines
are incorrectly processed by xargs. In these situations it is better to use
the `-0' option, which prevents such problems. When using this option you
will need to ensure that the program which produces the input for xargs also
uses a null character as a separator. If that program is GNU find for exam-
ple, the `-print0' option does this for you.
If any invocation of the command exits with a status of 255, xargs will stop
immediately without reading any further input. An error message is issued
on stderr when this happens.
也就是说查找的文件中如果含有空格和线,者xargs会出现报错。当加上-o后,他就可以识别。
find /tmp -name core -type f -print | xargs /bin/rm -f
Find files named core in or below the directory /tmp and delete them. Note that this will work incorrectly if there are
any filenames containing newlines or spaces.
find /tmp -name core -type f -print0 | xargs -0 /bin/rm -f
Find files named core in or below the directory /tmp and delete them, processing filenames in such a way that file or
directory names containing spaces or newlines are correctly handled.
注意,向find /tmp -name core -type f -print | xargs /bin/rm –f如果改成:
xargs 的作用是输入重定向。
Find /tmp –name core –type f –print |rm –f 则不会起作用。
cut -d: -f1 sudo find /home/liangyin/mrtgbackup/ -type f -print|xargs grep -rl "10.163.28.3.*"
/home/liangyin/mrtgbackup/b/mrtg/10.163.28.3_146800777.html
/home/liangyin/mrtgbackup/b/mrtg/10.163.28.3_146800785.html
/home/liangyin/mrtgbackup/b/mrtg/10.163.28.3_146800793.html
/home/liangyin/mrtgbackup/b/mrtg/10.163.28.3_146800801.html
/home/liangyin/mrtgbackup/b/mrtg/10.163.28.3_146800809.html
/home/liangyin/mrtgbackup/b/mrtg/10.163.28.3_146800817.html
-R, -r, --recursive
Read all files under each directory, recursively; this is equivalent to the -d recurse
option.
-l, --files-with-matches
Suppress normal output; instead print the name of each input file from which output would
normally have been printed. The scanning will stop on the first match.
-l 的意思找到内容后输出的是文件的形式,不是文件的内容。
而grep 默认情况下:输出的是文件的内容。
find -type f -name '*.png' | xargs -n1 | while read ABC; do echo $ABC && mv $ABC ${ABC%.png}.gif ; done
这里-n 意思是一个传N个选项给命令。这样查找更准确。
find -type f -name '*.png' |while read ABC; do mv $ABC ${ABC%.png}.gif;done
可以用这个命令来实现。注意:%
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/50921/showart_505630.html |
|