APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

2003/12/20 basename, dirname


© December 2003 Tony Lawrence

Very simple commands for breaking up filenames:

bash-2.05a$ basename /etc/passwd
passwd
bash-2.05a$ dirname /usr/lib/sendmail
/usr/lib
 

dirname this will return ".". So does dirname "" , which could be a problem under some odd conditions.

"basename" can also remove extensions, or more accurately suffixes:

bash-2.05a$ basename foo.tar .tar
foo
bash-2.05a$ basename foo.tar ar  
foo.t
bash-2.05a$ basename foo.tar oo.tar
f
 

However, it won't null out the file name:

bash-2.05a$ basename foo.tar foo.tar
foo.tar
 

There are equivalent functions in C, Perl, and probably every other language.


Got something to add? Send me email.





(OLDER)    <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

->
-> basename, dirname


Inexpensive and informative Apple related e-books:

Sierra: A Take Control Crash Course

Take Control of Parallels Desktop 12

Photos for Mac: A Take Control Crash Course

Take Control of Upgrading to El Capitan

Take Control of iCloud




More Articles by © Tony Lawrence




Printer Friendly Version

Have you tried Searching this site?

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us


Printer Friendly Version





Solving today's problems with yesterday's technology,someday (Kevin Brooks Clark)




Linux posts

Troubleshooting posts


This post tagged:

Scripting

Shell

UnixWords



Unix/Linux Consultants

Skills Tests

Unix/Linux Book Reviews

My Unix/Linux Troubleshooting Book

This site runs on Linode