요구 사항 1. 설명
다음 목록에있는 파일을 기존 :
[root@localhost logan]# ls
test1.txt test2.txt
TEST1, TEST2 : 우리는 같은 접미사없이 추출 파일 이름 만 필요
2. 구현 코드
[root@localhost logan]# for file_name in `ls ./ `;do basename $file_name .txt;done
test1
test2
3.basename 사용
3.1 구문
basename(选项)(参数)
3.2 옵션
--help:显示帮助;
--version:显示版本号。
3.3 명령 형식
basename 名称 [后缀]
basename 选项
3.4 실제 운동
# 显示文件名,不包含目录
[root@localhost logan]# basename /home/logan/test1.txt
test1.txt
# 显示文件名,不包含目录与后缀
[root@localhost logan]# basename /home/logan/test1.txt .txt
test1
#----或者:-s指定移出的后缀
[root@localhost logan]# basename -s .txt /home/logan/test1.txt
test1
# 将多个参数按照顺序输出
[root@localhost logan]# basename -a /home/logan/test1.txt /home/logan/test2.txt
test1.txt
test2.txt
# 显示最后一个目录的名字
[root@localhost logan]# basename /home/logan
logan