Absolute and Relative Paths

Absolute and Relative Paths


So, the top most directory in the file
system is the root directory. And we denote the root
directory with a slash. You can describe
the location of any file or directory in the file system,
with a full path beginning with a slash. The full path is called
the absolute path, and that means that it tells every step
that has to be taken from the root, or the absolute beginning
of the file system. Absolute paths are unambiguous and
easy to understand, but they can also be
inconvenient to work with, especially if you’re working
with deeply nested directories. To make things simpler,
we can use relative paths instead. A file’s relative path, is its location relative to
the current working directory. If you’re working with files in or near the current working directory,
this can save you a lot of typing. Every time you’ve referred
to a file by just its name, you’ve actually been
using a relative path. This is the simplest
sort of relative path. The shell looks for the specified file
name within the current directory. For example, if the current
working directory is ocean, then the relative path of
the clam directory is just clam. Rather than having the full
path from the root, we can just have the path
from the working directory. Oh, and cwd here is just an abbreviation
for current working directory. You could also write relative paths for
files and other directories. For example,
the relative path of the giant file, and the clam directory,
is just clam/giant. Notice that, unlike a full path, the relative
path does not start with a slash. That’s how you can tell a relative
path from an absolute one. You can also write relative paths for
items that are closer to the root. The special directory entry ‘..’
points from a directory to its parent. So, if you’re in /home/philip/ocean,
and you refer to ‘..’, you’re talking about
the directory /home/philip. And if you refer to ../mountain, you’re
referring to /home/philip/mountain. There’s also a special
entry which is just ‘.’. ‘.’ points from each
directory to itself. For example, because our current
working directory is ocean, if we use .,
that refers to /home/philip/ocean. Another handy shortcut is ~. ~ is an abbreviation for
your own home directory. By starting a relative path with ~, you can easily specify paths
relative to your own home directory.

Comments

  1. Post
    Author
  2. Post
    Author
  3. Post
    Author
  4. Post
    Author
  5. Post
    Author
    Andrew Cisneros

    that's actually quite sad that he processes and looks like a robot. You are human not robot snap out of it.

  6. Post
    Author
  7. Post
    Author
    Oguz Ucar

    Yesterday our constructor spent 5 hours to explain this yet left us totaly confused. Thanks for the video!

  8. Post
    Author
  9. Post
    Author
  10. Post
    Author
  11. Post
    Author
  12. Post
    Author
  13. Post
    Author
  14. Post
    Author
    Endoe Kronic

    Someone answer this then:
    When you type the pwd command, you notice that your current location on the Linux filesystem is the /usr/local directory. Answer the following questions, assuming that your current directory is /usr/local for each question.

    a. Which command could you use to change to the /usr directory using an absolute pathname?

    b. Which command could you use to change to the /usr directory using a relative pathname?

    c. Which command could you use to change to the /usr/local/share/info directory using an absolute pathname?

    d. Which command could you use to change to the /usr/local/share/info directory using a relative pathname?

    e. Which command could you use to change to the /etc directory using an absolute pathname?

    f. Which command could you use to change to the /etc directory using a relative pathname?

  15. Post
    Author
  16. Post
    Author
  17. Post
    Author
  18. Post
    Author
    timefeatherstorm

    cwd = current working directory
    relative path does not start with a slash
    ../ points to the parent directory
    . points each directory to itself
    ~ is a shortcut to your own home directory

    did i get this right?

  19. Post
    Author
  20. Post
    Author
  21. Post
    Author
  22. Post
    Author
    Hturt Yada

    So basically absolute path is the full path of a file and starts with a "/", relative path is the file name by itself and does not start with a "/"

Leave a Reply

Your email address will not be published. Required fields are marked *