Difference between ./ and / (relative path and Absolute path)


In web or desktop programming/command-prompt use, we often come through such situations where we have to use relative/absolute paths. Is there are any differences between the notation “./” and “/” ?

./

Yes, there are! When you use “./” we mean an relative path. Suppose, you are in the location http://www.somedomain.com/some_directory/index.html

Now, if you want to insert an Image file which is located at this directory “some_directory”, you can write following code in your index.html page:

<img src = "./myimage.jpg">

If you want to use an image from a directory “another_dir” on level up, you should use “../”

<img src = "../another_dir/another_image.jpg">

Both some_dir and another_dir are located under the home of your domain (www.somedomain.com).

/

Now, let’s talk about using “/”

“/” means beginning from the Root level of your file system. Suppose, in Linux, you want to Change your current working directory to the directory “etc”. Since “etc” is placed just in the Root directory of your file system (see the image below), you should type something like this in your command-prompt:

cd /etc

If you tried with the command “cd ./etc”, it wouldn’t work! Why? Because “./” means beginning from the Current Working directory. Normally, when you use a command-prompt it selects the user’s Home folder as current working directory. So if you want to go to a directory based on root level, you should use “/” instead of “./”

Image: Unix/Linux File System. See, the folder “etc” stays just below the “root” or “/”

About these ads

ReMo at Mozilla Reps, open-source enthusiast.

Tagged with: ,
Posted in Linux, Software Development, Tutorials, Web Development

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

To keep the Web Open
Web docs by developers, for developers on MDN Work <span>for</span> Mozilla
Firefox OS
Thanks for visiting my blog!
  • 479,469 hits from Aug, 2009
Follow

Get every new post delivered to your Inbox.