加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

bash – 手动指定输入时,如何对xargs使用-0选项?

发布时间:2020-12-15 22:21:40 所属栏目:安全 来源:网络整理
导读:我有 ~/bashpractice$lsdir3 dir1 我明白了 ~/bashpractice$xargs ls -l dir1 dir3dir1: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 file2dir3:total 0-rw-r--r-- 1 abc abc 0 2011-05-23 10:20 file1-rw
我有

~/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所说

-0 Change xargs to expect NUL (“”)
characters as separators,instead of
spaces and newlines. This is expected
to be used in concert with the -print0
function in find(1).

找 . -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只需要与组合一起使用.期.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读