Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 06-28-2012
Registered User
 
Join Date: Apr 2012
Posts: 7
Thanks: 1
Thanked 0 Times in 0 Posts
How to convert relative path to absolute path?

Hello Everyone,
I want to convert

Relative Path - /home/stevin/data/APP_SERVICE/../datafile.txt

to

Absolute Path - /home/stevin/data/datafile.txt

Is there a built-in tool in Unix to do this or any good ideas as to how can I implement this.

-Steve
Sponsored Links
    #2  
Old 06-28-2012
radoulov's Avatar
--
 
Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 5,468
Thanks: 139
Thanked 538 Times in 506 Posts
What OS?
Sponsored Links
    #3  
Old 06-28-2012
Scrutinizer's Avatar
Moderator
 
Join Date: Nov 2008
Location: Amsterdam
Posts: 7,352
Thanks: 144
Thanked 1,756 Times in 1,593 Posts
Generic method:

Code:
( cd path; pwd )

    #4  
Old 06-28-2012
Registered User
 
Join Date: Apr 2012
Posts: 7
Thanks: 1
Thanked 0 Times in 0 Posts
Scrutinizer: I don't think I follow your code. Can you please elaborate.

Radoulov: I am using Linux 2.6.18-194.el5
Sponsored Links
    #5  
Old 06-28-2012
radoulov's Avatar
--
 
Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 5,468
Thanks: 139
Thanked 538 Times in 506 Posts

Code:
readlink -f  /home/stevin/data/APP_SERVICE/../datafile.txt

There is an utility called realpath too.
Sponsored Links
    #6  
Old 06-28-2012
Scrutinizer's Avatar
Moderator
 
Join Date: Nov 2008
Location: Amsterdam
Posts: 7,352
Thanks: 144
Thanked 1,756 Times in 1,593 Posts
Quote:
Originally Posted by qwarentine View Post
Scrutinizer: I don't think I follow your code. Can you please elaborate.
[..]
Just try:

Code:
( cd /home/stevin/data/APP_SERVICE/../datafile.txt; pwd )

It is a generic method that should work on most Unix platforms..
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to change Absolute path to Relative path sahil_jammu Shell Programming and Scripting 4 05-31-2011 10:29 AM
absolute path for a script ran with relative path rss67 Shell Programming and Scripting 10 04-13-2010 07:48 AM
Help with absolute path and relative path mzero UNIX for Dummies Questions & Answers 1 03-02-2009 09:29 AM
$PWD shows absolute path vs path w/symbolic links kornshellmaven Shell Programming and Scripting 3 06-13-2007 12:15 PM
vi - replacing a relative path with absolute path in a file Yinzer955i UNIX for Dummies Questions & Answers 2 09-07-2006 11:47 AM



All times are GMT -4. The time now is 11:41 AM.