linux中数组、计算、获取文件类型
1、获取文件类型
[root@localhost ~]# filename="/root/data/aa.gz" [root@localhost ~]# echo ${filename##*.} gz [root@localhost ~]# filename="/root/data/aa.dat" [root@localhost ~]# echo ${filename##*.} dat [root@localhost ~]# var=/dir1/dir2/file.txt [root@localhost ~]# echo ${var##*/} file.txt [root@localhost ~]# echo ${var##*.} txt [root@localhost ~]# echo ${var%/*} /dir1/dir2 [root@localhost ~]# echo ${var%.*} /dir1/dir2/file
参考:https://www.cnblogs.com/nzbbody/p/4391802.html