【问题标题】:How to remove extension (and prefix) of filenames using `find` at the command line?如何在命令行使用“find”删除文件名的扩展名(和前缀)?
【发布时间】:2014-02-26 18:31:17
【问题描述】:

我已经编写了这个递归查找已编译 java 的类名的小命令。它递归地查找所有 *.class 文件,然后我尝试通过将 '/' 替换为 '.'、剥离前缀等来从中创建类名。

class_files=$(find ./build-tests -d -name \*.class -print | tr "\/" "." | cut -c15-10000)

我的 bash 脚本知识非常初级。但是经过一番搜索后,我遇到了使用 ${i%%.class} 删除 .class 后缀的想法,但我不确定如何将其添加到命令行的管道版本中?这可能吗?或者我是否需要使用循环并建立一个数组,然后加入该数组,以及所有这些?

【问题讨论】:

    标签: linux command-line filenames


    【解决方案1】:

    我不确定find 的-d 选项在您的调用中表示什么,但也许这就是您想要的:

    find ./build-tests -name "*.class" -print0 | xargs -0 -n1 -Ifoo basename foo .class
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-06-07
      • 2012-08-15
      • 2012-02-11
      • 1970-01-01
      • 1970-01-01
      • 2017-02-23
      相关资源
      最近更新 更多