LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-16-2014, 12:35 PM   #1
sigint-ninja
Member
 
Registered: Feb 2011
Location: Republic Of Ireland
Distribution: Debian,Centos,Slackware
Posts: 452

Rep: Reputation: 29
Linking files throwing me a bit...


having a bit of a problem with this:

[me@linuxbox playground]$ ln fun fun-hard
[me@linuxbox playground]$ ln fun dir1/fun-hard
[me@linuxbox playground]$ ln fun dir2/fun-hard
So now we have four instances of the file “fun”. Let's take a look our playground directory:

[me@linuxbox playground]$ ls -l
total 16
drwxrwxr-x 2 me me 4096 2008-01-14 16:17 dir1
drwxrwxr-x 2 me me 4096 2008-01-14 16:17 dir2
-rw-r--r-- 4 me me 1650 2008-01-10 16:33 fun
-rw-r--r-- 4 me me 1650 2008-01-10 16:33 fun-hard

why is dir1 and dir2 only showing 2 links? shouldnt they all be on 4??? as the fun file is linked to three other items, shouldnt they all share 4 links?
 
Old 10-16-2014, 12:40 PM   #2
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,260

Rep: Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948
You're looking at the links for the directory itself, not the contents of that directory.

Every directory will have at least two links:
1) its parent to it (/path/to/dir1)
2) a link to itself (/path/to/dir1/.)

Plus it will have a link for ".." in every subdirectory, if it has any subdirectories, eg:
/path/to/dir1/subdir/..

Last edited by suicidaleggroll; 10-16-2014 at 12:42 PM.
 
Old 10-16-2014, 12:44 PM   #3
sigint-ninja
Member
 
Registered: Feb 2011
Location: Republic Of Ireland
Distribution: Debian,Centos,Slackware
Posts: 452

Original Poster
Rep: Reputation: 29
yes suicidaleggroll i just realized that...i just found a good tutorial on youtube which explained
but what about dir1 and dir2??? why are they saying 2...shouldnt they be 1? i dont understand this...
 
Old 10-16-2014, 12:48 PM   #4
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,260

Rep: Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948
As I said above (you may have missed the edit):
Quote:
Every directory will have at least two links:
1) its parent to it (/path/to/dir1)
2) a link to itself (/path/to/dir1/.)

Plus it will have a link for ".." in every subdirectory, if it has any subdirectories, eg:
/path/to/dir1/subdir/..
 
Old 10-16-2014, 12:52 PM   #5
sigint-ninja
Member
 
Registered: Feb 2011
Location: Republic Of Ireland
Distribution: Debian,Centos,Slackware
Posts: 452

Original Poster
Rep: Reputation: 29
ok suicidaleggroll sorry for being thick...yes i see what you mean now...its just standard... i created a new dir and saw what you mean...thanks for that...i understand now...appreciated
 
Old 10-16-2014, 01:13 PM   #6
sigint-ninja
Member
 
Registered: Feb 2011
Location: Republic Of Ireland
Distribution: Debian,Centos,Slackware
Posts: 452

Original Poster
Rep: Reputation: 29
suicidaleggroll just a quick one...

in this:

[me@linuxbox playground]$ ln -s fun fun-sym
[me@linuxbox playground]$ ln -s ../fun dir1/fun-sym
[me@linuxbox playground]$ ln -s ../fun dir2/fun-sym

the first line i get...

but in the second and third line...why is there ../fun (are we not in the directory where fun is? why is it going up a directory to fun?

thanks again for your help
 
Old 10-16-2014, 01:22 PM   #7
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,260

Rep: Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948
That's just how ln -s works. The target needs to be written from the destination's perspective, if that makes sense.

If you did "ln -s fun dir1/fun-sym", then fun-sym would be pointing to "fun" in its own directory. You always need to be careful when creating symlinks using a relative path to a destination other than your cwd. You need to ask yourself "How would I get to the target from the destination (regardless of where your cwd is), and that's how you need to write the target.

I usually find it easiest to just cd to the destination directory and then symlink from there, using tab completion if necessary.

Last edited by suicidaleggroll; 10-16-2014 at 01:24 PM.
 
  


Reply


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Boost library linking problem with eureqa. 64 bit ubuntu daf_mcduff Linux - Software 1 04-13-2012 03:22 AM
[SOLVED] Crashes in throwing exceptions if code compiled in 32 bit explicity on 64 bit system gaurav.rustagi Programming 10 01-30-2012 07:11 AM
Recoll indexing throwing strange errors on some files. taylorkh Linux - Software 1 12-21-2010 03:28 AM
[SOLVED] Problem linking with RHEL 6.0 libraries (linrt.so, libm.so, libnsl.so) in 64 bit envi akonchada Linux - General 5 12-09-2010 04:49 AM
including /usr/include/linux/ header files throwing errors in SLES 10.2 deedhnd Linux - Server 9 08-19-2008 09:08 AM


All times are GMT -5. The time now is 07:26 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration