Sinisterly
{Linux Tips} Paths Edition: Relative vs. Absolute Paths - Printable Version

+- Sinisterly (https://sinister.li)
+-- Forum: Computers (https://sinister.li/Forum-Computers)
+--- Forum: Operating Systems (https://sinister.li/Forum-Operating-Systems)
+--- Thread: {Linux Tips} Paths Edition: Relative vs. Absolute Paths (/Thread-Linux-Tips-Paths-Edition-Relative-vs-Absolute-Paths)



{Linux Tips} Paths Edition: Relative vs. Absolute Paths - roger_smith - 09-09-2014

Welcome to another Linux Tips!

In today's tip we're going to talk about Relative vs Absolute paths. We'll start with absolute paths.

Let's say you're in a directory in the following path:

Code:
/home/bobby/Desktop/homework/secret/
let's also say you want to change to the /var/www/html/ directory. Well, that's easy, you can simply run the following:

Code:
cd /var/www/html/
and you will be moved to that directory. That is an example of an absolute path. Another example, let's use the same original directory (secret) and say you want to move to /home/bobby/, well you can do the same thing:

Code:
cd /home/bobby/
Basically, your location within the filesystem doesn't matter if you're utilizing absolute paths, because you're telling the system exactly where to move you to next.

Easy right? Absolute paths are not big deal. Now we'll look at relative paths, a little more tricky.

We'll say that we are in secret/ directory again (/home/bobby/Desktop/homework/secret/ in case you forgot). Now let's say you want to change to the Desktop directory using a relative path. That would look like

Code:
cd ../../
whaat??? you might think. Don't worry, I'll explain. If you issue a command that utilizes ../, that is referencing the directory above your current directory. So in our example of secret, a ../ references homework; another ../ references the directory about homework, in this case Desktop.

So let's say that there is another directory in Desktop we want to look at; let's call it movies. If we wanted to go from secret to movies, we could do this:

Code:
cd ../../movies/
that would take us from secret to homework, then homework to Desktop, then Desktop to movies. (note, the system doesn't actually do it that way, that's just how you can think about it when learning more about paths.)

There you have it, examples of absolute vs. relative path navigation, enjoy!


RE: {Linux Tips} Paths Edition: Relative vs. Absolute Paths - Eclipse - 09-09-2014

Thank you for the awesome share! I was in need of this a while back when I was trying to make fa-nigga work in Firefox.


RE: {Linux Tips} Paths Edition: Relative vs. Absolute Paths - Reiko - 09-09-2014

For anyone wondering "what does this have to do with hacking?" or "how can this help me hack?", look into file inclusion vulnerabilities. Roger's trying to educate everyone the proper way, and I commend him for that. However, a lot of this site's userbase are just going to skim this or disregard it if they're anything like I was when I was their age, unless they can immediately understand how it relates to their goal of being l33t h4x0rs.

Again, I'm not bashing your work Roger. I actually love it. I'm just trying to appeal to the lowest common denominator here Tongue

EDIT: Something that was not mentioned when dealing with paths is the special . path. It simply refers to the current directory.
If you're in /var/www already and you do this:
Code:
cd ./html
you'll end up in /var/www/html. You can also just do "cd html". I mentioned the . variant because it's useful in evading simplistic web-application firewalls. You can even do something like /var/www//////html or /var/www//././././././././../www//./../././././www///html and you'll still end up where you intended.


RE: {Linux Tips} Paths Edition: Relative vs. Absolute Paths - Oni - 09-09-2014

All very basic information, but I bet someone will find it useful. Thanks for teaching people!

(09-09-2014, 09:57 AM)Reiko Wrote: For anyone wondering "what does this have to do with hacking?" or "how can this help me hack?", look into file inclusion vulnerabilities. Roger's trying to educate everyone the proper way, and I commend him for that. However, a lot of this site's userbase are just going to skim this or disregard it if they're anything like I was when I was their age, unless they can immediately understand how it relates to their goal of being l33t h4x0rs.

Again, I'm not bashing your work Roger. I actually love it. I'm just trying to appeal to the lowest common denominator here Tongue

EDIT: Something that was not mentioned when dealing with paths is the special . path. It simply refers to the current directory.
If you're in /var/www already and you do this:
Code:
cd ./html
you'll end up in /var/www/html. You can also just do "cd html". I mentioned the . variant because it's useful in evading simplistic web-application firewalls. You can even do something like /var/www//////html or /var/www//././././././././../www//./../././././www///html and you'll still end up where you intended.

I don't know if they will skim through it. When I first started using Linux (years ago, now) I would have loved to have seen stuff like this. Instead, I picked up the information over time. That being said, I used Linux as my primary operating system for a good amount of time, so it wasn't necessarily about hacking. It was about understanding how to use an operating system.


RE: {Linux Tips} Paths Edition: Relative vs. Absolute Paths - roger_smith - 09-09-2014

thanks for all the feedback everyone. I'm going to try and do a couple of these things a week, of varying experience levels.