【问题标题】:How to find all files in a folder w/o the folder itself如何在没有文件夹本身的文件夹中查找所有文件
【发布时间】:2017-06-30 15:36:59
【问题描述】:

我尝试了以下命令:

>> ls abc
1  2  3
>> find abc -name "*" -print0
abcabc/1abc/2abc/3
>> find abc -name "*" -print0 | xargs -0 ls
abc/1  abc/2  abc/3

abc:
1  2  3

如果我使用*,似乎也可以通过find找到.。可以要求 find 不回.吗?

我也试过-not -path "."。它不起作用。

【问题讨论】:

  • 如果您对文件夹不感兴趣,而只对文件感兴趣,那么您可能正在寻找 find abc -type f...

标签: linux shell find


【解决方案1】:

您可以指定相对于您指定的起点的最小深度

$ cd -- "$(mktemp --directory)"
$ mkdir a
$ touch a/b a/c
$ find a -mindepth 1 -name "*"
a/c
a/b

【讨论】:

    【解决方案2】:

    您还可以通过这种方式使用 -type f 主文件来限制仅文件:

    $ mkdir abc
    $ touch abc/{1..3}
    $ ls abc
    1   2   3
    $ find abc -type f 
    abc/1
    abc/2
    abc/3
    

    那么find 将只显示目录作为文件路径显示的一部分:

    $ mkdir abc/efg
    $ mkdir abc/xyz
    $ touch abc/efg/{4..6}
    $ find abc -type f 
    abc/1
    abc/2
    abc/3
    abc/efg/4
    abc/efg/5
    abc/efg/6
    

    最后一个例子没有显示.abc/xyz

    【讨论】:

    • ... 或 ! -type d!这将允许使用 symlinksdevicespipes,用于示例...
    猜你喜欢
    • 2011-05-14
    • 1970-01-01
    • 2012-08-05
    • 2013-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多