我正在使用find /tmp/tartest/ -maxdepth 1 -mindepth 1 -not -type l
命令获取除符号链接之外的所有文件和目录的列表.这给了我以下o/p:
/tmp/tartest/hi.txt
/tmp/tartest/hello1.txt
/tmp/tartest/testdir
/tmp/tartest/hello.txt
Run Code Online (Sandbox Code Playgroud)
注意/tmp/tartest/testdir
是否可以用/
?结束?/tmp/tartest/testdir/
找到所有目录?
我在shell脚本中使用这个o/p.
find
表达式可以有分支逻辑.附加两个后续操作的默认方式是-a
("和"),但您也可以-o
手动使用("或").
因此,使用GNU find
(这里使用因为它支持-printf
,让你指定任意格式字符串):
find /tmp/tartest -maxdepth 1 \
-type d -printf '%p/\n' \
-o -printf '%p\n'
Run Code Online (Sandbox Code Playgroud)
注意:
-maxdepth 1
是全球性的,因此它适用于所有分支机构.-type d -printf '%p/\n'
打印目录名称(内容-type d
为true),/
后面跟着它们.-o -printf '%p\n'
重视上述用或条件,使得printf
不/
只是运行时,事情就不会匹配-type d
. 归档时间: |
|
查看次数: |
34 次 |
最近记录: |