擴展

2010-05-04 54 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