linux中文件夹有空格,Linux下遍历有空格的文件夹或文件名的方法

本文参考引用自hostloc ID:嗷嗷 命令作者:志明

在Linux下用脚本或命令遍历目录下文件夹或文件名的时候,假如文件名里有空格的时候,我们把这些文件名放进用空格分割的数组里会变成几个文件名。

这个时候,我们只需要加一个print0就可以了。

[root@localhost ~]# find -name "*.txt"

./1 2.txt

./a b.txt

[root@localhost ~]# find -name "*.txt" -print0

./1 2.txt./a b.txt[root@localhost ~]#find -name "*.txt" -print0|xargs ls -l

xargs: WARNING: a NUL character occurred in the input. It cannot be passed through in the argument list. Did you mean to use the --null option?

ls: cannot access './1': No such file or directory

ls: cannot access '2.txt': No such file or directory

ls: cannot access 'b.txt': No such file or directory

[root@localhost ~]# find -name "*.txt" -print0|xargs -0 ls -l

-rw-r--r--. 1 root root 0 Jul 26 20:23 './1 2.txt'

-rw-r--r--. 1 root root 0 Jul 26 20:23 './a b.txt'

[root@localhost ~]#

691dbbf97624730ea3a73e9a9c111c89.png

sicnature ---------------------------------------------------------------------

Your current IP address is: 49.81.81.143

Your IP address location: 江苏省徐州市电信

Your IP address country and region: 中国

3211c715c0bf352c3fa72980bf0cc419.png

Your current browser is:

b2cb575f9cbd2e36961b3bf406c3355c.png

Your current system is:

mac.png

Original content, please indicate the source:

同福客栈论坛 | 蟒蛇科普 | 海南乡情论坛 | JiaYu Blog

sicnature ---------------------------------------------------------------------

Welcome to reprint. Please indicate the source https://www.myzhenai.com/post/3538.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值