Find the answer to your Linux question:
Results 1 to 8 of 8
What are the reasons one chooses to use Absolute pathing over Relative pathing and/or Relative pathing over Absolute pathing?...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Mar 2005
    Location
    Fort Lauderdale, Florida
    Posts
    2

    Absolute vs Relative Pathing


    What are the reasons one chooses to use Absolute pathing over Relative pathing and/or Relative pathing over Absolute pathing?

  2. #2
    Linux Guru
    Join Date
    May 2004
    Location
    forums.gentoo.org
    Posts
    1,817
    For what?

    A couple of possible reasons:
    Relative paths take less space (fewer characters) than absolute paths.
    Relative paths are more portable as long as the files refering to ne another are kept together, that is in the same relative positions.
    /IMHO
    //got nothin'
    ///this use to look better

  3. #3
    Linux Enthusiast
    Join Date
    Jan 2005
    Posts
    575
    Assume that I have a script in dir1 which among other things accesses file1 also in dir1.Since both file1 and script reside in the same directory the name of the file can appear simply as file1 inside
    script ie I only need to use a relative pathname.
    But if I try to run script from console when my working directory is not dir1 then it will not find file1 at all.Even worse it may be that
    my working directory also has a file named file1.Imagine the results if script modifies file1.It will modify the wrong file and I may not even realize it at the time.

    So I think that absolute pathnames tend to be safer when used inside programmes.Actually they're safer when typing at the command line as well but it would be too much of a drag to always type complete paths.

    To make a script more portable one way is to use an
    eviroment variable which contains an absolute directory path and the script mentions files relative to that path.So there's less possibility to refer to the wrong file but when switching to a different computer one only needs to change the value of the variable and the script will still work.

  4. $spacer_open
    $spacer_close
  5. #4
    Just Joined!
    Join Date
    Jan 2005
    Posts
    15

    Best Approach

    The best approach is to use absolute paths in combination with a single, centralized configuration location. This could be at the top of your primary executable script file, it could be in an XML file referenced from a single location, or something of this nature. This way, you have total portability with a few keystrokes to update the initial path.

  6. #5
    Just Joined!
    Join Date
    Mar 2005
    Location
    Fort Lauderdale, Florida
    Posts
    2
    Quote Originally Posted by drakebasher
    For what?

    A couple of possible reasons:
    Relative paths take less space (fewer characters) than absolute paths.
    Relative paths are more portable as long as the files refering to ne another are kept together, that is in the same relative positions.
    Thanks drakebasher, I agree with you about Relative paths... They take less space and are more portable than Absolute paths. These are two reasons why someone would use a Relative path instead of an Absolute path.
    Why would someone rather use an Absolute path instead of a Relative path to navigate? The only reasons I can come up with is that when using an Absolute path to navigate, one might believe it to be safer or when developing, the developer would use an Absolute path instead of a Relative path in their script. What do you think?

  7. #6
    scm
    scm is offline
    Linux Engineer
    Join Date
    Feb 2005
    Posts
    1,044
    And for added security, you should really fullpath all your commands, ie "/bin/grep" instead of just "grep" to avoid the possibility of someone putting a malicious script called grep in one of your PATHed directories and wreaking havoc.

  8. #7
    Linux Enthusiast
    Join Date
    Jan 2005
    Posts
    575
    And of course when executing commands , an absolute path
    will be quicker since the system will know immediately what
    the file is.

  9. #8
    Linux Newbie
    Join Date
    Mar 2005
    Location
    Bangalore, INDIA
    Posts
    122

    u knoe the topic

    imagine having to copy files from somewhwre down in ur home folder to the ur desktop.
    try copying bothways u will know the advantage
    bye
    Portability is for people who cannot programme

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •