[Linuxは](接尾辞なし)のファイル名でディレクトリを表示するには

要件の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

おすすめ

転載: www.cnblogs.com/OliverQin/p/12502790.html