All your base…

Master Ian (whom I would link to, if his blog were not continually DOWN), showed me a very simple yet useful command:

1
basename

.

You give it the path to a file, it gives you the filename and extension. If you also give it the extension, it just gives you the filename. Thus:

sam@ZenSam:~$ basename unique-ip-list.csvunique-ip-list.csvsam@ZenSam:~$ basename unique-ip-list.csv .csvunique-ip-list

This could be quite useful in shell scripting, to grab a list of desired for various purposes. One implementation I thought of right off: If you wanted to throw an error message for the usage of a command in a script, instead of having it display “See /usr/bin/zip for details” or something similar, you could run it through basename, and get a better looking name.

Post to Twitter Post to Delicious Post to Digg Post to Reddit

No related posts.

Related posts brought to you by Yet Another Related Posts Plugin.

This entry was posted in CLI and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>