Linux命令(107)之basename

简介: Linux命令(107)之basename

inux命令之basename

1.basename介绍
linux命令basename是用来从文件路径中获取文件的基本名称

2.basename用法
basename [参数] NAME

basename参数
参数 说明
-a 支持多个参数,并将每个参数视为一个NAME
-s 移除后缀
-z 使用NUL而不是换行符分隔输出
--help 显示帮助信息
--version 显示版本信息
3.实例
3.1.获取文件名称
命令:

basename /root/ztj.txt

[root@rhel77 ~]# basename /root/ztj.txt
ztj.txt
[root@rhel77 ~]#
3.2.获取文件名称,并移除其后缀
命令:

basename -s .txt /root/ztj.txt

[root@rhel77 ~]# basename -s .txt /root/ztj.txt
ztj
[root@rhel77 ~]#
3.3.同时获取多个文件的文件名称
命令:

basename -a /root/ztj.txt /root/zzz.txt

[root@rhel77 ~]# basename -a /root/ztj.txt /root/zzz.txt
ztj.txt
zzz.txt
[root@rhel77 ~]#
3.4.同时获取多个文件的文件名称,并移除其后缀
命令:

basename -a -s .txt /root/ztj.txt /root/zzz.txt

[root@rhel77 ~]# basename -a -s .txt /root/ztj.txt /root/zzz.txt
ztj
zzz
[root@rhel77 ~]#
3.5.获取文件目录
命令:

basename /root/test

OR

basename /root/test/

[root@rhel77 ~]# basename /root/test
test
[root@rhel77 ~]# basename /root/test/
test
[root@rhel77 ~]#
3.6.查看basename版本
命令:

basename --version

[root@rhel77 ~]# basename --version
basename (GNU coreutils) 8.22
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by David MacKenzie.
[root@rhel77 ~]#
3.7.查看basename帮助
命令:

basename --help

[root@rhel77 ~]# basename --help
Usage: basename NAME [SUFFIX]
or: basename OPTION... NAME...
Print NAME with any leading directory components removed.
If specified, also remove a trailing SUFFIX.

Mandatory arguments to long options are mandatory for short options too.
-a, --multiple support multiple arguments and treat each as a NAME
-s, --suffix=SUFFIX remove a trailing SUFFIX
-z, --zero separate output with NUL rather than newline
--help display this help and exit
--version output version information and exit

Examples:
basename /usr/bin/sort -> "sort"
basename include/stdio.h .h -> "stdio"
basename -s .h include/stdio.h -> "stdio"
basename -a any/str1 any/str2 -> "str1" followed by "str2"

GNU coreutils online help: http://www.gnu.org/software/coreutils/
For complete documentation, run: info coreutils 'basename invocation'
[root@rhel77 ~]#
————————————————
版权声明:本文为CSDN博主「小黑要上天」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/z19861216/article/details/134069226

目录
相关文章
|
3天前
|
SQL 缓存 监控
|
3天前
|
前端开发 Linux Shell
|
2天前
|
Linux
Linux系统ps命令
这些是一些常见的 `ps`命令选项和用法,用于查看系统中运行的进程及其相关信息。您可以根据需要选择合适的选项以满足您的任务要求。
11 0
|
3天前
|
存储 Linux Shell
linux课程第二课------命令的简单的介绍2
linux课程第二课------命令的简单的介绍2
|
3天前
|
Linux C语言 数据安全/隐私保护
linux课程第二课------命令的简单的介绍3
linux课程第二课------命令的简单的介绍3
|
3天前
|
监控 Unix Linux
如何使用 Linux less 命令?
【4月更文挑战第25天】
13 1
如何使用 Linux less 命令?
|
3天前
|
JSON 网络协议 Linux
Linux ip命令:网络的瑞士军刀
【4月更文挑战第25天】
9 1
|
3天前
|
安全 Linux C语言
linux课程第一课------命令的简单的介绍
linux课程第一课------命令的简单的介绍
|
3天前
|
网络协议 Linux Shell
|
3天前
|
NoSQL Linux Shell
2.Docker常用命令(linux)
2.Docker常用命令(linux)