The arch command is used to print the machine’s architecture. For example:
$ arch i686
The basename command allows you to strip off components from filenames that aren’t required. Following is the tool’s syntax:
basename NAME [SUFFIX]basename OPTION... NAME...
And here’s what the man page says about it:
basename - strip directory and suffix from filenamesPrint NAME with any leading directory components removed. If specified, also remove a trailing SUFFIX.
By default, if you run the ‘basename’ command with a full path to a file as an input, the command returns the filename in output. For example, when I executed the following command:
I got the following output:
Handling multiple inputs
To let Basename handle multiple inputs, you need to use the -a command-line option. For example, when I executed the following command:
basename -a /home/bryanpwo/Downloads/analytics.pdf /home/himanshu/Pictures/test.png
And here’s the output I got:
Strip file extensions
Sometimes, you might only want to fetch the filename, but not its extension. Well, this can be done using the -s command-line option (which requires you to pass the suffix as input).
For example, the following command:
basename -s .pdf /home/bryanpwo/Downloads/analytics.pdf
produced this output:
Make each line output end with NUL
By default, the newline character is used as a separator in output. However, if you want, you can force basename to use NUL as the separator. This can be done using the -z command-line option.
basename -az /home/himanshu/Downloads/analytics.pdf /home/himanshu/Pictures/test.png
And here’s the output:
So you don’t see the NUL character here. For that, you need to redirect the output to a file, and then open the file in an editor like nano. Here’s what nano showed:
As you can see, basename isn’t a very feature-rich command – the options it provides are limited.Follow us: