分页: 1 / 1

关于xargs的小BUG

发表于 : 2015-04-10 10:57
iamcook84
suse@linux-337q:~/downs> find . -name '*.txt'
./d.txt
./新建 文件夹/m.txt
suse@linux-337q:~/downs> find . -name '*.txt' | xargs rm -rf
suse@linux-337q:~/downs> find . -name '*.txt'
./新建 文件夹/m.txt

为什么删不掉m.txt?有问题吧。

我换一种方法:
suse@linux-337q:~/downs> find . -name '*.txt' -exec rm -rf {} \;
suse@linux-337q:~/downs> find . -name '*.txt'
suse@linux-337q:~/downs>
这回好了,为什么是这样呢?好像只有在带空格的中文文件夹中才会有此问题。

Re: 关于xargs的小BUG

发表于 : 2015-04-10 14:55
astolia
你不去读一下xargs的manpage么?
Because Unix filenames can contain blanks and new‐
lines, this default behaviour is often problematic;
filenames containing blanks and/or newlines are in‐
correctly 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 example, the -print0 op‐
tion does this for you.