bash获取特定目录下所有文件的全路径

find directory | sort -u |sed 'N;/^/(./+/)/n/1/!P;D' 获取directory目录下所有文件的全路径

 

find                                           获取路径,但是包括目录

sort -u                                       排序

sed 'N;/^/(./+/)/n/1/!P;D'           排除目录的路径

       N  读入下一行至模式空间

       /^/(./+/)/n/1/   匹配模式空间中,第一个换行(/n)符号前与后面有重复的,也就是匹配第一个换行符前的字符在后面是否再次出现,如:

              /home/user /n /home/user/date

                   /1        /n

      !P   如果匹配成功,不打印,否则打印

      D    删除模式空间开头到第一个/n(含)之间的内容,即上面红色部分

 

 

再贴上sed 的N P D的解释:

P: 就是输出模式空间开头到第一个/n之间的内容

D:
If pattern space contains no newline, start a normal new cycle as if the d command was issued. Otherwise, delete text in the pattern space up to the first newline, and restart cycle with the resultant pattern space, without reading a new line of input.
(是删除模式空间开头到第一个/n(含)之间的内容,并且控制流跳到脚本的第一条语句。这里一定要注意这句话“and restart cycle with the resultant pattern space, without reading a new line of input.”,即它是在不改变当前行号的情况下,从头执行的。)
这句话也充分的说明了,为什么很多人不愿意读中文翻译版书籍的原因。:-)

N: Add a newline to the pattern space, then append the next line of input to the pattern space. If there is no more input then sed exits without processing any more commands. (追加下一个输入行到模式空间后面并在二者间嵌入一个新行,改变当前行号码。如果没有下一个可处理的行,则退出)

注意大小写n d的区别

来自  http://scmbob.org/sed_npd_analyse.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值