扩展

2010-05-04 97 views
7

我在同一个目录下的一些文件(在UNIX文件系统),看起来像之前获取文件名?扩展

即。 a.txt,b.xml,c.properties部分?

回答

9
$ basename a.txt.name .name 
a.txt 
+0

尼斯后缀选项。谢谢! – 2010-05-04 16:44:46

4
$ file="a.txt.name" 
$ file="${file%.*}" 
$ echo "$file" 
a.txt 
2

如果命名约定始终是foo.bar.other,那么这是很简单的:

ls * | cut -d. -f1,2