LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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, 02:54 AM   #1
limdel
Member
 
Registered: May 2009
Location: Ho Chi Minh City, Vietnam
Distribution: CentOS - FEDORA
Posts: 59

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, 02:59 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,850

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
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, 03:05 AM   #3
limdel
Member
 
Registered: May 2009
Location: Ho Chi Minh City, Vietnam
Distribution: CentOS - FEDORA
Posts: 59

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

${var##*/} did the trick

have a nice day.
 
  


Reply



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 10:54 AM
[SOLVED] get last folder in path xjx424 Linux - Newbie 17 04-13-2011 11:38 AM
[SOLVED] how to retrieve mv deleted folder hemanthm17 Linux - Newbie 2 06-22-2010 02:38 PM
obexftp, how to retrieve the whole folder? frenchn00b Linux - General 1 11-08-2009 01:07 PM
How do you address a folder in another path Redbug Linux - Newbie 1 08-27-2008 11:06 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:50 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
Open Source Consulting | Domain Registration