LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-01-2009, 09:48 AM   #1
jmcejuela
LQ Newbie
 
Registered: Apr 2009
Posts: 6

Rep: Reputation: 0
How to split the file name from the path in BASH?


What's the easiest way to obtain the file name and the path in 2 independent strings in a command like:

rm /path/file

so

string1=/path
string2=file

How the bash commands do it?


Thank you for your time
 
Old 04-01-2009, 09:49 AM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
dirname
 
Old 04-01-2009, 09:51 AM   #3
jmcejuela
LQ Newbie
 
Registered: Apr 2009
Posts: 6

Original Poster
Rep: Reputation: 0
OK, I guess it's simple done with dirname and basename :P
 
Old 04-01-2009, 10:39 AM   #4
Hobbletoe
Member
 
Registered: Sep 2004
Location: Dayton, Oh
Distribution: Linux Mint 17
Posts: 150

Rep: Reputation: 18
Or, if you have it stored in a variable such as ${a} (for lack of a better name), you can get the directory and the file using ...

Code:
dir=${a%/*}
file=${a##*/}
 
  


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
Bash or PHP: Split csv file based on field value? guest Programming 4 02-06-2009 12:57 AM
bash: how to split a text file in two unequal parts Humbro Programming 7 11-23-2007 07:15 AM
list entire file path in bash ajk48n Programming 1 07-26-2006 01:05 AM
bash: split text file iluvatar Programming 4 08-22-2005 08:58 AM
How to parse full path of file name in bash ? hq4ever Programming 2 03-28-2005 03:31 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:54 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