LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 03-28-2013, 02:13 AM   #1
CollieJim
Member
 
Registered: Mar 2005
Distribution: Gentoo, Kubuntu
Posts: 444

Rep: Reputation: 19
recursive directory loop


Why do some directories have recursive links?

grep reports them and appears smart enough to ignore them.
 
Old 03-28-2013, 03:25 AM   #2
pan64
Senior Member
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 4,928

Rep: Reputation: 1305Reputation: 1305Reputation: 1305Reputation: 1305Reputation: 1305Reputation: 1305Reputation: 1305Reputation: 1305Reputation: 1305Reputation: 1305
usually by mistake
 
Old 03-28-2013, 04:12 AM   #3
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 806
Blog Entries: 2

Rep: Reputation: 203Reputation: 203Reputation: 203
Can you show an example?
 
Old 03-28-2013, 07:18 AM   #4
CollieJim
Member
 
Registered: Mar 2005
Distribution: Gentoo, Kubuntu
Posts: 444

Original Poster
Rep: Reputation: 19
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#
 
Old 03-28-2013, 07:47 AM   #5
pan64
Senior Member
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 4,928

Rep: Reputation: 1305Reputation: 1305Reputation: 1305Reputation: 1305Reputation: 1305Reputation: 1305Reputation: 1305Reputation: 1305Reputation: 1305Reputation: 1305
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.
 
Old 03-28-2013, 08:09 AM   #6
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 806
Blog Entries: 2

Rep: Reputation: 203Reputation: 203Reputation: 203
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.
 
Old 03-28-2013, 08:31 AM   #7
pan64
Senior Member
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 4,928

Rep: Reputation: 1305Reputation: 1305Reputation: 1305Reputation: 1305Reputation: 1305Reputation: 1305Reputation: 1305Reputation: 1305Reputation: 1305Reputation: 1305
Quote:
Originally Posted by linosaurusroot View Post
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)
 
Old 03-28-2013, 08:43 AM   #8
Ginola
Member
 
Registered: Sep 2012
Location: UK
Distribution: CentOS, RHEL
Posts: 56

Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
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
 
Old 03-28-2013, 09:04 AM   #9
suitianshi
LQ Newbie
 
Registered: Feb 2013
Posts: 14

Rep: Reputation: Disabled
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
 
Old 03-28-2013, 10:39 AM   #10
pan64
Senior Member
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 4,928

Rep: Reputation: 1305Reputation: 1305Reputation: 1305Reputation: 1305Reputation: 1305Reputation: 1305Reputation: 1305Reputation: 1305Reputation: 1305Reputation: 1305
Quote:
Originally Posted by Ginola View Post
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.
 
Old 03-29-2013, 05:44 PM   #11
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 2,237

Rep: Reputation: 577Reputation: 577Reputation: 577Reputation: 577Reputation: 577Reputation: 577
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.
 
  


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
Recursive directory search janel10 Linux - Newbie 2 08-26-2008 06:28 AM
"Permission denied" and "recursive directory loop" when searching for string in files mack1e Linux - Newbie 5 06-12-2008 07:38 AM
Desktop link in recursive loop rocket777 Ubuntu 4 04-26-2007 11:36 PM
recursive directory permissions confused_user Linux - Security 7 07-11-2006 06:02 AM
recursive directory traversal klfreese Linux - Newbie 2 08-20-2003 07:27 PM


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

Main Menu
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