how to use basename command

Forum rules
Before you post please read this

how to use basename command

Postby kaykav on Fri Dec 14, 2012 12:22 pm

I found a command 'basename'. Man pages are most always confusing. As an example I type... basename <path>. As a result I get the last file name of the path. So now what? What do I do with this result?
I fail to see the use of this command. It tells you what to do but not what to do with the result. Anyone explain? Thank you...
kaykav
Level 3
Level 3
 
Posts: 149
Joined: Tue Jan 06, 2009 12:09 am
Location: crossville tn

Linux Mint is funded by ads and donations.
 

Re: how to use basename command

Postby xenopeek on Fri Dec 14, 2012 12:31 pm

basename gives you just the file name for a given argument. It's mostly used in scripts where for example you get a list of full paths from some command and you only want to use the file names.
User avatar
xenopeek
Level 21
Level 21
 
Posts: 14666
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

Re: how to use basename command

Postby kaykav on Fri Dec 14, 2012 1:26 pm

Ok thanks for that . I thought I was missing the jist of the command. Thanks again
kaykav
Level 3
Level 3
 
Posts: 149
Joined: Tue Jan 06, 2009 12:09 am
Location: crossville tn

Re: how to use basename command

Postby pgmer6809 on Wed Jan 02, 2013 12:12 am

The complement of basename is dirname.
so
Code: Select all
 basename /usr/share/progname
returns the result progname
Code: Select all
dirname  /usr/share/progname
returns the result /usr/share without the trailing slash.
Code: Select all
 dirname /usr
returns /
Code: Select all
dirname   myMusic/
returns .
Code: Select all
 basename myMusic/
returns myMusic
pgmer6809
Level 2
Level 2
 
Posts: 96
Joined: Sun Mar 04, 2012 9:06 pm


Return to Scripts & Bash

Who is online

Users browsing this forum: No registered users and 2 guests