2008年(91)
分类: LINUX
2008-03-23 22:07:22
也就是说查找的文件中如果含有空格和线,者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 < /etc/passwd | sort | xargs echo
Debian-exim backup bin cjl daemon games gnats irc list lp mail man news nobody proxy root snmp sshd sync sys uucp www-data xiaowang
从这个命令更可以看出他的输入重定向功能。
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
可以用这个命令来实现。注意:%