LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 11-18-2004, 06:23 AM   #1
Gins
Senior Member
 
Registered: Jul 2004
Location: Germany
Distribution: open SUSE 11.0, Fedora 7 and Mandriva 2007
Posts: 1,638

Rep: Reputation: 46
Absolute and relative paths


Could you explain me the difference between absolute path and relative path?

/export/home/heden/rhost

The above is said to be absolute path.

Is it because the forward slash?

In Windows, we talked about a single path. There are no two paths in Windows.

What are those absolute and relative paths?
 
Old 11-18-2004, 06:41 AM   #2
oneandoneis2
Senior Member
 
Registered: Nov 2003
Location: London, England
Distribution: Ubuntu
Posts: 1,460

Rep: Reputation: 46
Quote:
Is it because the forward slash?
Pretty much - by putting that / at the start, you're saying "Start at the root directory, and work along"

If you don't put the / at the front, you're saying "Start from the current directory"

If you put ../ at the front, you're saying "Go back one directory and then start looking"

And if you put ~/ at the front, you're saying "Look in my home directory"

So, to sum up, let's say you're in the directory /etc/wibble

If you say cd /foo/bar you're asking to go to the directory /foo/bar

If you say cd foo/bar you're asking to go to the directory /etc/wibble/foo/bar

If you say cd ../foo/bar you're asking to go to the directory /etc/foo/bar

And if you say cd ~/foo/bar you're asking to go to the directory /home/yourname/wibble/foo/bar

Last edited by oneandoneis2; 11-18-2004 at 06:43 AM.
 
Old 11-18-2004, 06:57 AM   #3
Gins
Senior Member
 
Registered: Jul 2004
Location: Germany
Distribution: open SUSE 11.0, Fedora 7 and Mandriva 2007
Posts: 1,638

Original Poster
Rep: Reputation: 46
Thanks for the answer.

So the following is an abslote path.
/export/home/heden/rhost


If I take the forward slashes away, it becomes a relative path.
export home heden rhost
Please tell me if I am wrong. However, without slashes, it looks strange.


You have beautifully explained the meanings of / , ../ and ~/ . I just want to know the meaning of the ./


You said / this means start at the root directory as well as the current directory. Was it a mistake? Shouldn't it be ./

Please reply me when possible. I appreciate very much your explainations.
 
Old 11-18-2004, 08:35 AM   #4
oneandoneis2
Senior Member
 
Registered: Nov 2003
Location: London, England
Distribution: Ubuntu
Posts: 1,460

Rep: Reputation: 46
Quote:
If I take the forward slashes away, it becomes a relative path.
export home heden rhost
Please tell me if I am wrong. However, without slashes, it looks strange.
No, it's only the first / that you take away.
export /home/heden/rhost is absolute
export home/heden/rhost is relative to the current working directory

Quote:
I just want to know the meaning of the ./
./ refers to the current directory

/ = root directory
./ = current directory
../ = parent directory

You often don't have to bother with ./ - if you're in /foo and you want to switch to /foo/bar, you can use either:

cd /foo/bar
cd ./bar
or just
cd bar
- so naturally this is the one you'd usually use

When the ./ DOES become useful is for things like moving files to the current directory, eg mv /foo/bar/* ./

Last edited by oneandoneis2; 11-18-2004 at 08:39 AM.
 
Old 11-08-2008, 06:57 PM   #5
Gatorbug
LQ Newbie
 
Registered: Nov 2008
Location: FT. Bragg, NC
Distribution: Red Hat Enterprise Linux v5
Posts: 2

Rep: Reputation: 0
Noobs 1st Post...

Ok hello all,(first post)

I am a noob to Linux but not to computers. I work for a College Network MIS department and I am taking a Red Hat Academy course for familiarization. I have several windows and Cisco networks certifications but, Linux is a new animal to me. I have the following question from one of my assignments for which I am becoming greatly confused.

The chapter is on linkings. Hard/soft I can complete the #6 question below but I can not seem to make the command for the relative linking(#7) below work. I grade the task and it gives me partial credit for the command but it says that my link does not resolve to ../../usr/share/doc (home/student/usr/share/doc)

6.Create a soft link to the /usr/share/doc directory, called docabs, using an absolute reference.

[######4625@localhost ~]$ ln -s usr/share/doc ~/docabs (This worked)

7.Create a soft link to the ../../usr/share/doc directory, called docrel, using a relative reference. (Note: depending on the location of your home directory, you may need to add or remove some .. references from the proceeding filename. Include enough so that the the soft link is a true relative reference to the /usr/share/doc directory.

Below are three commands that I have tried that produce output but it wont pass the grade script that checks the exercise. I am not missing much I am sure I am close probably more with the second command than the first but it still is incorrect. I know this will be something simple or something I am just overlooking but its vexing me terribly. Any help would be appreciated. I hate to trouble you folks with such trivial stuff but I am a "noob" so I wont ever learn if I don't ask.

[######4625@localhost ~]$ ln -s usr/share/doc ../######4625/docrel
[######4625@localhost ~]$ ln -s usr/share/doc ../../docrel
[######4625@localhost ~]$ ln -s /../../usr/share/doc docrel

{Content from Academy site.}
If you have finished the exercise correctly, you should be able to reproduce output similar to the following.

[student@station student]$ ls -l
total 12
.......content removed........
lrwxrwxrwx 1 student student 14 Jul 21 10:03 docabs -> /usr/share/doc
lrwxrwxrwx 1 student student 19 Jul 21 10:03 docrel -> ../../usr/share/doc

Thanks so much for your time.
Gatorbug
 
Old 11-08-2008, 07:18 PM   #6
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 115Reputation: 115
You should start a new thread rather than resurrect a 4 year old thread.

Quote:
6.Create a soft link to the /usr/share/doc directory, called docabs, using an absolute reference.

[######4625@localhost ~]$ ln -s usr/share/doc ~/docabs (This worked)
This should not have worked because, as written, you have used a relative reference to the directory you are linking to. Do you see where?

Quote:
Below are three commands that I have tried that produce output but it wont pass the grade script that checks the exercise. I am not missing much I am sure I am close probably more with the second command than the first but it still is incorrect. I know this will be something simple or something I am just overlooking but its vexing me terribly. Any help would be appreciated. I hate to trouble you folks with such trivial stuff but I am a "noob" so I wont ever learn if I don't ask.

[######4625@localhost ~]$ ln -s usr/share/doc ../######4625/docrel
[######4625@localhost ~]$ ln -s usr/share/doc ../../docrel
[######4625@localhost ~]$ ln -s /../../usr/share/doc docrel
/ means start at root of filesystem (absolute reference).
./ means current directory
../ means go up one directory from the current directory then proceed.
../../ means go up two directories then proceed.
../../../ means go up three directories then proceed.

And so forth.
 
Old 11-08-2008, 09:48 PM   #7
Gatorbug
LQ Newbie
 
Registered: Nov 2008
Location: FT. Bragg, NC
Distribution: Red Hat Enterprise Linux v5
Posts: 2

Rep: Reputation: 0
Quote:
Originally Posted by jiml8 View Post
You should start a new thread rather than resurrect a 4 year old thread.



This should not have worked because, as written, you have used a relative reference to the directory you are linking to. Do you see where?



/ means start at root of filesystem (absolute reference).
./ means current directory
../ means go up one directory from the current directory then proceed.
../../ means go up two directories then proceed.
../../../ means go up three directories then proceed.

And so forth.
Sorry for posting here... but The thread was not closed and it fit the problem that I had. So I posted here to keep from creating duplicate threads in your forum. I didn't check the date on the thread when I posted.

The above command that You said should not have worked.(due to a relative reference)was correct.
[######4625@localhost ~]$ ln -s /usr/share/doc ~/docabs (This worked)
I just pasted it poorly... I left off the / at the beginning. I had not noticed that I left it off. Devils in the details.

Second, Without knowing it you also solved my problem. Thank you.

The command should have been:

[######4625@localhost ~]$ ln -s ../../usr/share/doc docrel

(This worked)You pointing out my error in this post fixed my problem.
I wont tag this forum again... You probably ought to close it then. As it still searchable and open to replies.

Thanks again,
Gatorbug
 
  


Reply

Tags
file, references, relative, structure


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
bash: ln and relative paths tortle Programming 8 05-10-2010 06:50 AM
Symbolic Links, directories, and relative paths (../). Can it be done? jimwillsher Linux - Newbie 1 03-11-2005 06:27 PM
relative/absolute paths in Java djgerbavore Programming 2 10-26-2004 09:01 PM
program that generates relative paths? TheMaXX Linux - Software 1 10-21-2003 03:17 PM
Automatically resolving WINDOWS paths to pre-configured Linux paths gazzy Linux - General 1 09-05-2003 11:15 PM


All times are GMT -5. The time now is 05:46 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration