2018-11-10 13:13:07 +00:00
|
|
|
---
|
|
|
|
layout: page
|
2018-11-10 21:05:37 +00:00
|
|
|
category-page: intermediate
|
|
|
|
category-title: Intermediate commands
|
|
|
|
tags: basename suffix prefix name
|
2018-11-10 13:13:07 +00:00
|
|
|
author: Fabiano Fenini
|
2018-11-10 21:05:37 +00:00
|
|
|
title: basename
|
2018-11-18 20:38:56 +00:00
|
|
|
previous-page: pages/cmd/interm/base64.html
|
|
|
|
next-page: pages/cmd/interm/bash.html
|
2018-11-10 13:13:07 +00:00
|
|
|
---
|
2018-11-12 10:47:50 +00:00
|
|
|
The <code>basename</code> command deletes any prefix ending with the last slash "/" character
|
2018-11-10 21:05:37 +00:00
|
|
|
present in string and also a suffix.
|
2018-11-10 13:13:07 +00:00
|
|
|
|
2018-11-12 10:47:50 +00:00
|
|
|
<h3>Usage</h3>
|
2018-11-10 21:05:37 +00:00
|
|
|
The default basename command syntax is:
|
2018-11-10 13:13:07 +00:00
|
|
|
|
|
|
|
<pre>
|
|
|
|
basename [flags] [string] [suffix]
|
|
|
|
</pre>
|
|
|
|
|
2018-11-10 21:05:37 +00:00
|
|
|
Where [flags] are the cat flags, read below for more info, the string command is
|
2018-11-12 10:47:50 +00:00
|
|
|
the pathname and the suffix, if indicated, will be also deleted.<br><br>
|
2018-11-10 13:13:07 +00:00
|
|
|
|
2018-11-12 10:47:50 +00:00
|
|
|
<h3>Flags</h3>
|
2018-11-10 13:13:07 +00:00
|
|
|
|
2018-11-10 21:05:37 +00:00
|
|
|
Here are some of the most common basename flags:
|
2018-11-10 13:13:07 +00:00
|
|
|
|
|
|
|
<ul>
|
2018-11-16 19:47:01 +00:00
|
|
|
<li><b>-a</b>: Every aregument is treated as a string </li>
|
|
|
|
<li><b>-s</b>: The suffix is taken as its argument </li>
|
|
|
|
<li><b>-a</b>: Supports multiple arguments and they will be treated as a name </li>
|
2018-11-10 13:13:07 +00:00
|
|
|
</ul>
|
2018-11-19 12:53:45 +00:00
|
|
|
|
|
|
|
<h3>Example<h3>
|
|
|
|
|
2018-11-19 12:57:32 +00:00
|
|
|
<pre>
|
2018-11-19 12:53:45 +00:00
|
|
|
basename /USI/command
|
2018-11-19 12:57:32 +00:00
|
|
|
</pre>
|
|
|
|
|
|
|
|
The shell will output this:
|
2018-11-19 12:53:45 +00:00
|
|
|
|
2018-11-19 12:57:32 +00:00
|
|
|
<pre>command</pre>
|
|
|
|
|