LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   recursive directory loop (https://www.linuxquestions.org/questions/linux-software-2/recursive-directory-loop-4175455870/)

CollieJim 03-28-2013 02:13 AM

recursive directory loop
 
Why do some directories have recursive links?

grep reports them and appears smart enough to ignore them.

pan64 03-28-2013 03:25 AM

usually by mistake

linosaurusroot 03-28-2013 04:12 AM

Can you show an example?

CollieJim 03-28-2013 07:18 AM

Code:

jim@HOME-HP:/usr/bin/X11# ls -al
total 191720
-rwxr-xr-x 1 root  root      35264 Nov 20 06:25 [*
...
-rwsr-sr-x 1 root  root      10184 Jan  4 00:23 X*
lrwxrwxrwx 1 root  root          1 Mar 19 23:50 X11 -> ./
...
-rwxr-xr-x 1 root  root        2642 Mar  7  2012 x11perfcomp*
jim@HOME-HP:/usr/bin/X11#


pan64 03-28-2013 07:47 AM

yes, it definitely looks like a mistake. The root cause is that the command ln -s <from> <to> will give different resuslt depending on the <from> (if it was a file or a dir) and depending on <to> if it exists or not and <to> is a dir or file.
usually creating link into a non-existing dir will give you surprising result. Using relative path may also lead to strange results (especially when the current working directory is not the one you need to use). I think that happened in your case.

linosaurusroot 03-28-2013 08:09 AM

At least that's only a symbolic link and not a hard link causing an actual fault to be unravelled.

I also suspect the [ in /usr/bin/X11 is an error.

pan64 03-28-2013 08:31 AM

Quote:

Originally Posted by linosaurusroot (Post 4920500)
At least that's only a symbolic link and not a hard link causing an actual fault to be unravelled.

I also suspect the [ in /usr/bin/X11 is an error.

hard link cannot be seen by ls and also you are not allowed to make hard link on dirs (because it is really hard to detect)

Ginola 03-28-2013 08:43 AM

Quote:

Originally Posted by pan64 (Post 4920514)
hard link cannot be seen by ls and also you are not allowed to make hard link on dirs (because it is really hard to detect)

maybe not directly, but with

Code:

ls -li
anything with the same inode is essentially a hard link, but the number of links are shown also...

Code:

[ginola@wopr LQ]$ date > one.txt
[ginola@wopr LQ]$ ls -li
total 4
1593327 -rw-rw-r--. 1 ginola ginola 29 Mar 28 13:38 one.txt
[ginola@wopr LQ]$ ln one.txt two.txt
[ginola@wopr LQ]$ ls -li
total 8
1593327 -rw-rw-r--. 2 ginola ginola 29 Mar 28 13:38 one.txt
1593327 -rw-rw-r--. 2 ginola ginola 29 Mar 28 13:38 two.txt
[ginola@wopr LQ]$ ln one.txt three.txt
[ginola@wopr LQ]$ ls -li
total 12
1593327 -rw-rw-r--. 3 ginola ginola 29 Mar 28 13:38 one.txt
1593327 -rw-rw-r--. 3 ginola ginola 29 Mar 28 13:38 three.txt
1593327 -rw-rw-r--. 3 ginola ginola 29 Mar 28 13:38 two.txt


suitianshi 03-28-2013 09:04 AM

from my perspective , the only advantage to use soft link into a directory is that you needn't type so many letter...

for example

ln -s /home/user/2013/02/10/work /home/workfolder

cd /home/workfolder

pan64 03-28-2013 10:39 AM

Quote:

Originally Posted by Ginola (Post 4920521)
maybe not directly, but with

Code:

ls -li
.... the number of links are shown also...

You are right. Actually hard to tell what filenames are hardlinked to the same inode (the numbers are shown)


symbolic links are used for many purposes, not only shorten the path.
For example you can easily change different versions of a file by only replacing the link.

jpollard 03-29-2013 05:44 PM

Actually, you can't make a hardlink to a directory - it is already set. The problem with making hard links to directories is that it makes fsck fail (the directory tree is no longer a tree).

A directory file can only have two links - one pointing to itself (.) and the one from its parent directory.

During fsck, a symbolic link is treated as an ordinary file with data. Directories though must have a parent directory, and must have an entry for themselves. A parent directory must exist, and there can only be one parent directory.


All times are GMT -5. The time now is 01:19 PM.