bash – 手动指定输入时,如何对xargs使用-0选项?
我有
~/bashpractice$ls dir3 dir1 我明白了 ~/bashpractice$xargs ls -l dir1 dir3 dir1: total 0 -rw-r--r-- 1 abc abc 0 2011-05-23 10:19 file1 -rw-r--r-- 1 abc abc 0 2011-05-23 10:19 file2 dir3: total 0 -rw-r--r-- 1 abc abc 0 2011-05-23 10:20 file1 -rw-r--r-- 1 abc abc 0 2011-05-23 10:20 file2 但是当我这样做时,我收到了一个错误 ~/bashpractice$xargs -0 ls -l dir1 dir3 ls: cannot access dir1 dir3 : No such file or directory abc@us-sjc1-922l:~/bashpractice$xargs -0 ls -l dir1 dir3 ls: cannot access dir1 dir3 : No such file or directory 如何在为xargs指定-0选项时获取列表? 解决方法
例如 – 正如男人xargs所说
找 . -print0 | xargs -0 echo -0告诉xargs一件事. “不要用空格分隔输入,而是使用NULL char”.当你需要处理文件和/或名称中包含空格的目录时,它通常与find结合使用很有用. 有更多的命令可以使用-print0 – 例如grep -z. 编辑 – 基于评论: 请参见塞思的答案或: ls -1 | perl -pe 's/n/ /;' > null_padded_file.bin xargs -0 < null_padded_file.bin 但是是一个奇怪的,为什么要使用-0如果你不需要使用它?比如“为什么要删除文件,如果不存在?”.简单地说,如果输入为空填充,则-0只需要与组合一起使用.期. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |