【问题标题】:Finding files with certain extension [duplicate]查找具有特定扩展名的文件[重复]
【发布时间】:2019-07-21 21:05:38
【问题描述】:

当尝试查找具有特定扩展名的某些文件时,例如 .*c

如果我输入下面的代码

find folder1 -type f -name '*c'

结果就像

folder1/filename1.c

folder1/filename2.c

如果我只想要文件名,不包括如下文件的目录,我将如何更改代码?

filename1.c

filename2.c

【问题讨论】:

    标签: bash shell


    【解决方案1】:

    来自man find 下的-printf 选项您会看到:

    %f     File's name with any leading directories removed (only the last element).
    

    使用它:

    find folder1 -type f -name '*.c' -printf '%f\n'
    

    附注小心图案。你想要*.c,而不是.*c*c

    【讨论】:

      【解决方案2】:

      你可以像这样通过管道将它传递给awk 命令

      find folder1 -type f -name '*.c' | awk -F '/' '{ print $NF }'
      

      【讨论】:

        猜你喜欢
        • 2011-08-21
        • 2011-03-10
        • 1970-01-01
        • 2011-03-13
        • 2012-01-26
        • 2012-10-13
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多