代码之家  ›  专栏  ›  技术社区  ›  ryanprayogo

在扩展名之前获取文件名

  •  7
  • ryanprayogo  · 技术社区  · 15 年前

    我在同一个目录(在Unix文件系统中)中有一些文件,如下所示:

    a.txt.name
    b.xml.name
    c.properties.name
    
    a.txt.name2
    b.xml.name2
    c.properties.name2
    

    我怎样才能在 name name2 部分使用shell命令?

    I. a.txt , b.xml , c.properties 部分?

    4 回复  |  直到 10 年前
        1
  •  9
  •   Thomas    15 年前
    $ basename a.txt.name .name
    a.txt
    
        2
  •  4
  •   Dennis Williamson    15 年前
    $ file="a.txt.name"
    $ file="${file%.*}"
    $ echo "$file"
    a.txt
    
        3
  •  2
  •   Ram    10 年前

    如果命名约定总是 其他人 ,那么这就足够简单了:

    ls * | cut -d. -f1,2
    
        4
  •  1
  •   Tim Cooper    12 年前

    看看bash字符串操作函数。本页将为您提供最便捷的方式:

    http://tldp.org/LDP/abs/html/string-manipulation.html