LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Absolute and relative paths (https://www.linuxquestions.org/questions/linux-general-1/absolute-and-relative-paths-256350/)

Gins 11-18-2004 05:23 AM

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?

oneandoneis2 11-18-2004 05:41 AM

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

Gins 11-18-2004 05:57 AM

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.

oneandoneis2 11-18-2004 07:35 AM

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/* ./

Gatorbug 11-08-2008 05:57 PM

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

jiml8 11-08-2008 06:18 PM

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.

Gatorbug 11-08-2008 08:48 PM

Quote:

Originally Posted by jiml8 (Post 3335684)
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


All times are GMT -5. The time now is 03:07 PM.