【问题标题】:Alternative way to find all files in a folder and subfolders在文件夹和子文件夹中查找所有文件的替代方法
【发布时间】:2014-05-21 07:56:29
【问题描述】:

下面的命令是否有任何替代方法来查找文件夹和子文件夹中的文件。

find . | egrep '\./[^/]+/[^/]+/[^/]+'

注意:我不想要只获取文件的目录

【问题讨论】:

  • 注意:我不想要目录我只想获取文件
  • 我认为这个问题与编程无关。这是纯粹的工具使用问题...

标签: linux file unix grep find


【解决方案1】:

此外,您可以指定文件扩展名列表作为搜索选项:

find . -type f -name "*.js" -o -name "*.ros" -o -name "*.php"

上面的例子,只会在特定文件夹和子文件夹下显示带有 *.ros、*.php 和 *.js 作为文件扩展名的文件名。

【讨论】:

    【解决方案2】:

    为什么不直接使用 find 呢? 如果您想限制深度,我不确定您的问题。如果是这样:

    find . -type f -depth 2 -print
    

    如果你只是想查找文件

    find . -type f -print
    

    如果你只是想查找目录

    find . -type d -print
    

    如果 -print 不能让你的船漂浮,你也可以使用 -ls。

    find . -type f -ls
    

    【讨论】:

    • 如果我们不确定深度怎么办?
    • 别说了。 -type f 只查找文件。
    • Grr AIX 无法测试。最后可能需要 -print。
    • 我已经尝试过 find 。 -type f 它没有给出正确的输出
    • 你得到了什么输出,为什么不正确?
    猜你喜欢
    • 1970-01-01
    • 2016-08-12
    • 1970-01-01
    • 2020-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多