1、basename的语法是:basename[选项][参数]
其中:
选项:为有路径信息的文件名,如/home/test/test.txt
参数:指文件扩展名
2、如果在编程过程中,想取得纯粹的文件名,则该命令将非常有用。下面举两个例子:
3、需要把某个路径下的文件名赋值给变量file_name:
假设文件的路径是/home/test/test.txt,把test赋值给file_name:
[c.plm@localhost ~]$ file_name=`basename /home/test/test.txt `
[c.plm@localhost ~]$ echo $file_name
test.txt
[c.plm@localhost ~]$

4、需要把某个路径下的文件名赋值给变量file_name,并去掉扩展名:
同样假设文件的路径是/home/test/test.txt,把test赋值给file_name:
[c.plm@localhost ~]$ file_name=`basename /home/test/test.txt .txt`
[c.plm@localhost ~]$ echo $file_name
test
[c.plm@localhost ~]$

5、linux哲学是,用功能单一的命令,通过组合、输入、输出,完成复杂的任务。我每天都会写出3-5个命令示例,希望对您有所帮助。