LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-16-2013, 03:54 AM   #1
limdel
Member
 
Registered: May 2009
Location: Ho Chi Minh City, Vietnam
Distribution: CentOS 6.4, FEDORA 18 x64, Linux Mint 15 x64
Posts: 57

Rep: Reputation: 15
How to retrieve last folder from a path


Hi,

I wonder how could we extract the name of the last folder from a path.
The path represent the mount point of a CD/DVD extracted from "df" command.
I have a .sh script with variable $mountpoint set as "/media/user/mycdname" and i would like to retrieve "mycdname".
Is their a split string function somewhere ? or any other way to get it ?

Thanks in advance
Laurent
 
Old 09-16-2013, 03:59 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,133

Rep: Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273
have you tried the basename command?
also there is a shell variable expansion to do that:
${var##*/}
 
1 members found this post helpful.
Old 09-16-2013, 04:05 AM   #3
limdel
Member
 
Registered: May 2009
Location: Ho Chi Minh City, Vietnam
Distribution: CentOS 6.4, FEDORA 18 x64, Linux Mint 15 x64
Posts: 57

Original Poster
Rep: Reputation: 15
@pan64, thank you saved my day.

${var##*/} did the trick

have a nice day.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Retrieve the exact URL path devilboy09 Programming 4 01-27-2012 11:54 AM
[SOLVED] get last folder in path xjx424 Linux - Newbie 17 04-13-2011 12:38 PM
[SOLVED] how to retrieve mv deleted folder hemanthm17 Linux - Newbie 2 06-22-2010 03:38 PM
obexftp, how to retrieve the whole folder? frenchn00b Linux - General 1 11-08-2009 02:07 PM
How do you address a folder in another path Redbug Linux - Newbie 1 08-27-2008 12:06 PM


All times are GMT -5. The time now is 07:03 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration