Linux命令(107)之basename

linux命令之basename

1.basename介绍

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

2.basename用法

basename [参数] NAME

|-----------|-----------------------|
| 参数 | 说明 |
| -a | 支持多个参数,并将每个参数视为一个NAME |
| -s | 移除后缀 |
| -z | 使用NUL而不是换行符分隔输出 |
| --help | 显示帮助信息 |
| --version | 显示版本信息 |
[basename参数]

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 ~]# 
相关推荐
有时.不昰沉默2 小时前
ubuntu 20.04 启动直接进入 tty1,而非 图形界面
linux·运维·ubuntu·tty1
济6172 小时前
linux 系统移植(第七期)----U-Boot 图形化配置--添加自定义菜单-- Ubuntu20.04
linux·运维·服务器
松涛和鸣2 小时前
DAY56 ARM Cortex-A Bare Metal
linux·服务器·c语言·开发语言·arm开发·数据库
星陨772 小时前
OpenStack私有云平台API接口练习
linux·运维·网络·openstack
YongCheng_Liang2 小时前
Docker 核心概念与价值详解:从理论到实战安装指南
运维·docker·容器
别再下雨辽2 小时前
开发板通过 VSCode Remote-SSH 反向转发复用 PC 代理排障总结
linux·ide·笔记·vscode·ssh
蒜香拿铁2 小时前
【第五章】python判断语句if
java·服务器·python
Kratzdisteln2 小时前
【Linux】Docker容器中快速部署VNC远程桌面环境
linux·运维·docker
魔众2 小时前
轻量级云文件系统simple-file-server,电脑秒变存储服务器
运维·服务器
追光的孩子2 小时前
window服务器添加samwaf防火墙遇到的问题和解决方案
运维·服务器