1)提取文件名

[root@server0 thread]# echo $var
/mnt/thread/2.py
[root@server0 thread]# echo ${var##*/}
2.py

2)提取目录

[root@server0 thread]# echo $var
/mnt/thread/2.py
[root@server0 thread]# echo ${var%/*}
/mnt/thread

3)提取后缀

[root@server0 thread]# tmp=${var##*/}
[root@server0 thread]# echo ${tmp#*.}
Py

/mnt/thread/2.py
[root@server0 thread]# echo $tmp
2.py
[root@server0 thread]# echo ${tmp%.*}
2

用命令提取文件和目录名
用basename提取文件名

[root@server0 thread]# echo $var
/mnt/thread/2.py
[root@server0 thread]# echo $(basename $var)
2.Py
3.`

提取不带后缀的文件名
提取文件名和目录

用dirname提取目录名

[root@server0 thread]# dirname $var
/mnt/thread

相关文章:

  • 2021-08-08
  • 2022-02-02
  • 2022-01-04
  • 2021-05-24
  • 2021-11-18
猜你喜欢
  • 2022-12-23
  • 2022-03-07
  • 2023-02-16
  • 2022-12-23
  • 2021-08-12
  • 2021-10-31
相关资源
相似解决方案