How to use the Linux basename command

How to use the Linux basename command

01. Command Overview

basename - strip directories and suffixes from file names

The basename command is used to print the base name of a directory or file. The basename and dirname commands are often used in command substitution in shell scripts to specify output file names that differ from the specified input file names.

02. Command format

basename name[suffix]
basename Option

03. Common options

Show NAME with directory components removed. If SUFFIX is specified, the trailing SUFFIX is removed as well.
--help 
 Display help information and then end --version
 Display version information and then end

04. Reference examples

4.1 Display file names without directories

[deng@localhost ~]$ basename /home/deng/scott_data.sql 
scott_data.sql
[deng@localhost ~]$

4.2 Display file name, excluding directory and suffix

[deng@localhost ~]$ basename /home/deng/scott_data.sql .sql
scott_data
[deng@localhost ~]$ 

4.3 Display file name, excluding directory and suffix

-s specifies the suffix to remove

[deng@localhost ~]$ basename -s .sql /home/deng/scott_data.sql 
scott_data
[deng@localhost ~]$

4.4 Output multiple parameters in order

[deng@localhost test]$ basename -a ./20190712.log ./20190713.log 
20190712.log
20190713.log
[deng@localhost test]$ ls

4.5 Display the name of the last directory

If the last one is a directory, then the name of the last directory will be displayed.

[deng@localhost test]$ basename /home/deng/share/
share
[deng@localhost test]$ 

This is the end of this article about how to use the Linux basename command. For more information about the Linux basename command, please search 123WORDPRESS.COM’s previous articles or the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Detailed explanation of the usage of Linux top command
  • Usage of linux cut command
  • Detailed explanation of sudo command in Linux system
  • How to automatically execute commands or scripts at Linux startup
  • 4 ways to execute Linux system commands in Python
  • Detailed usage of Linux ipcs command and ipcrm command
  • Detailed explanation of Linux ls command parameters

<<:  jQuery implements sliding tab

>>:  Websocket+Vuex implements a real-time chat software

Recommend

Detailed explanation of CSS pre-compiled languages ​​and their differences

1. What is As a markup language, CSS has a relati...

Zen HTML Elements Friends who use zen coding can collect it

html ¶ <html></html> html:xml ¶ <h...

Share the pitfalls of MySQL's current_timestamp and their solutions

Table of contents MySQL's current_timestamp p...

Html comments Symbols for marking text comments in Html

HTML comments, we often need to make some HTML co...

js code that associates the button with the enter key

Copy code The code is as follows: <html> &l...

Details of watch monitoring properties in Vue

Table of contents 1.watch monitors changes in gen...

Vue.js uses Element-ui to implement the navigation menu

This article shares the specific code for impleme...

Front-end state management (Part 2)

Table of contents 1. Redux 1.1. Store (librarian)...

A complete list of meta tag settings for mobile devices

Preface When I was studying the front end before,...

In-depth understanding of MySQL master-slave replication thread state transition

Preface The basic principle of MySQL master-slave...

Detailed explanation of crontab scheduled execution command under Linux

In LINUX, periodic tasks are usually handled by t...

How to place large images in a small space on a web page

Original source: www.bamagazine.com There are nar...

JavaScript Timer Details

Table of contents 1. Brief Introduction 2. setInt...