shell提取文件名和目录名
2017-09-18 16:17
302 查看
${}用于字符串的读取,提取和替换功能,可以使用${} 提取字符串
1.提取文件名:
[root@localhost test]# var=/mnt/aaa/test/test.txt [root@localhost test]# echo ${var##*/} test.txt
2.提取后缀:
[root@localhost test]# echo ${var##*.} txt
3.提取文件名,不带后缀:
[root@localhost test]# tmp=${var##*/} [root@localhost test]# echo $tmp test.txt [root@localhost test]# echo ${tmp%.*} test
4.提取目录:
[root@localhost test]# echo ${var%/*} /mnt/aaa/test
5.使用文件目录的专有命令basename和dirname:
注:basename命令使用(),而不是{}
提取文件名:
[root@localhost test]# echo $(basename $var) test.txt
提取文件名,不带后缀:
[root@localhost test]# echo $(basename $var .txt) test
提取目录:
[root@localhost test]# dirname $var /mnt/aaa/test [root@localhost test]# echo $(dirname $var) /mnt/aaa/test
参考:shell学习..
相关文章推荐
- jenkins中使用脚本来节省资源空间和使用shell提取文件名或目录名的方法
- Linux的shell提取文件名和目录名的方法
- shell 提取文件名和目录名的一些方法
- shell 提取文件名和目录名
- Linux shell 之 提取文件名和目录名的一些方法
- shell 获取指定目录下文件名
- windows 下提取目录下所有文件的文件名
- shell脚本 过滤出对应目录下的所有png文件名
- Linux shell 之 提取文件名和目录名的一些方法
- 用shell脚本将当前目录中每个文件的文件名及其内容显示出来
- Shell学习:切分文件名提取文件扩展名或提取文件名
- shell 遍历目录 批量解压文件名含有某字符串及特定后缀的文件
- Linux shell 之 提取文件名和目录名的一些方法
- Linux shell 之 提取文件名和目录名的一些方法
- shell递归输出文件名和目录名
- Linux shell 提取文件名和目录名的一些方法(转)
- Linux shell 之 提取文件名和目录名的一些方法
- 20120803 AIX_shell监控指定目录下是否有指定的文件名的文件生产
- Linux shell 之 提取文件名和目录名的一些方法
- Linux shell 之 提取文件名和目录名的一些方法