|
Home > Archive > Unix Programming > September 2007 > second column of ls -l doesn't show number of hard links
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
second column of ls -l doesn't show number of hard links
|
|
| Jerry Fleming 2007-08-17, 7:24 am |
| Hi,
It's said that the second column of ls -l shows the number of hard links
to the file. The file under investigation has 15 links. But when I run
find / -samefile ./myfile -print, it shows only one. After all, I don't
think that I had created all these hard links, or soft ones. So what
exactly does the second column mean?
Thanks.
| |
| Robert Gamble 2007-08-17, 1:20 pm |
| On Aug 17, 5:47 am, Jerry Fleming <jerry.flem...@saybot.com> wrote:
> Hi,
>
> It's said that the second column of ls -l shows the number of hard links
> to the file. The file under investigation has 15 links. But when I run
> find / -samefile ./myfile -print, it shows only one. After all, I don't
> think that I had created all these hard links, or soft ones. So what
> exactly does the second column mean?
The second column should be the number of links. Is the file in
question a directory?
Robert Gamble
| |
| Ben Bacarisse 2007-08-17, 1:20 pm |
| Jerry Fleming <jerry.fleming@saybot.com> writes:
> Hi,
>
> It's said that the second column of ls -l shows the number of hard
> links to the file. The file under investigation has 15 links. But when
> I run find / -samefile ./myfile -print, it shows only one. After all,
> I don't think that I had created all these hard links, or soft
> ones. So what exactly does the second column mean?
OK, first check that myfile is not a directory with 13
sub-directories. If is it all is as it should be, but I doubt you
would have posted in that case! Next...
I'd check with another program such as stat (if you have it) just to
get a second opinion. You might be using an odd version of ls (or
maybe even one whose behaviour has been customised by environment
variable settings). Check also what ls is running (I've seen distros
that have it as an alias by default).
If stat confirms the multiple links, and find does not find them, your
file system may be messed up -- un-mount it and fsck it.
--
Ben.
| |
| Logan Shaw 2007-08-17, 1:20 pm |
| Ben Bacarisse wrote:
> Jerry Fleming <jerry.fleming@saybot.com> writes:
[vbcol=seagreen]
> If stat confirms the multiple links, and find does not find them, your
> file system may be messed up -- un-mount it and fsck it.
There are other possibilities. For instance, the other links may be
obscured by a filesystem mounted on top of the directory that contains
them:
touch a
mkdir b
for i in 1 2 3 4 5
do
ln a b/"$i"
done
mount /dev/whatever `pwd`/b
Now when you do the 'find', you will not find the files '1' through '5',
but the link count on 'a' should still reflect them.
Or, to put it another way, 'find' and 'ls' reflect what you see at the
vfs layer, but the link count is something that exists at the layer of
the individual filesystem.
- Logan
| |
| Ben Bacarisse 2007-08-17, 1:20 pm |
| Logan Shaw <lshaw-usenet@austin.rr.com> writes:
> Ben Bacarisse wrote:
>
>
>
> There are other possibilities. For instance, the other links may be
> obscured by a filesystem mounted on top of the directory that contains
> them:
Yes, that is a good point (I said "may" because I was pretty sure
there could be other reasons for the discrepancy).
To the OP: does the filesystem containing "myfile" have other FSs
mounted within it? If so, unmount these, and check find again.
The links reported by stat can only be from withing the same
filesystem, so you only need to unmount those that might be "on top"
of it. If in doubt, post the output of mount.
--
Ben.
| |
| SM Ryan 2007-08-17, 1:20 pm |
| Jerry Fleming <jerry.fleming@saybot.com> wrote:
# Hi,
#
# It's said that the second column of ls -l shows the number of hard links
# to the file. The file under investigation has 15 links. But when I run
# find / -samefile ./myfile -print, it shows only one. After all, I don't
# think that I had created all these hard links, or soft ones. So what
# exactly does the second column mean?
Do you mean find -print or find -ls (or find -print | xargs ls -l)?
find -ls is a slightly different format from ls -l.
--
SM Ryan http://www.rawbw.com/~wyrmwif/
GERBILS
GERBILS
GERBILS
| |
| Jerry Fleming 2007-08-22, 1:23 am |
| SM Ryan wrote On 2007年08月18日 01:19, :
> Jerry Fleming <jerry.fleming@saybot.com> wrote:
> # Hi,
> #
> # It's said that the second column of ls -l shows the number of hard links
> # to the file. The file under investigation has 15 links. But when I run
> # find / -samefile ./myfile -print, it shows only one. After all, I don't
> # think that I had created all these hard links, or soft ones. So what
> # exactly does the second column mean?
>
> Do you mean find -print or find -ls (or find -print | xargs ls -l)?
> find -ls is a slightly different format from ls -l.
>
> --
> SM Ryan http://www.rawbw.com/~wyrmwif/
> GERBILS
> GERBILS
> GERBILS
No, I use exactly find / -samefile ./myfile -print.
| |
| Jerry Fleming 2007-08-22, 1:23 am |
| Ben Bacarisse wrote On 2007年08月17日 21:16, :
> Jerry Fleming <jerry.fleming@saybot.com> writes:
>
>
> OK, first check that myfile is not a directory with 13
> sub-directories. If is it all is as it should be, but I doubt you
> would have posted in that case! Next...
>
> I'd check with another program such as stat (if you have it) just to
> get a second opinion. You might be using an odd version of ls (or
> maybe even one whose behaviour has been customised by environment
> variable settings). Check also what ls is running (I've seen distros
> that have it as an alias by default).
>
> If stat confirms the multiple links, and find does not find them, your
> file system may be messed up -- un-mount it and fsck it.
>
Yes, it is a directory, but there are no 13 sub-directories -- even
there are, I was wondering that the sub-dir are not hard links to the
parent directory.
I did a `stat`, and it is consistent with ls.
| |
| Jerry Fleming 2007-08-22, 1:23 am |
| Ben Bacarisse wrote On 2007年08月17日 21:16, :
> Jerry Fleming <jerry.fleming@saybot.com> writes:
>
>
> OK, first check that myfile is not a directory with 13
> sub-directories. If is it all is as it should be, but I doubt you
> would have posted in that case! Next...
>
> I'd check with another program such as stat (if you have it) just to
> get a second opinion. You might be using an odd version of ls (or
> maybe even one whose behaviour has been customised by environment
> variable settings). Check also what ls is running (I've seen distros
> that have it as an alias by default).
>
> If stat confirms the multiple links, and find does not find them, your
> file system may be messed up -- un-mount it and fsck it.
>
No, there are no 13 sub-dir, no is my ls old -- I am working on Ubuntu
Feisty, which is very new. No mysterious alias, no unknown mounts, no
anything uncertain, because the system is newly installed.
I tried with other systems (i.e, gentoo linux), and get the same
confusing result. So I am sure no fsck is needed, but my understanding
of ls and hard links will have to be reformed 
| |
| Barry Margolin 2007-08-22, 1:23 am |
| In article <faga5c$fdm$1@news.cn99.com>,
Jerry Fleming <jerry.fleming@saybot.com> wrote:
> Ben Bacarisse wrote On 2007年08月17日 21:16, :
>
> Yes, it is a directory, but there are no 13 sub-directories -- even
> there are, I was wondering that the sub-dir are not hard links to the
> parent directory.
The ".." entry in each subdirectory is a hard link to the original
directory. The link count of a directory is 2+subdirectories, because
each subdirectory has a ".." link, the directory itself has a "." link,
and its parent directory has a link to the directory.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
| |
| Ben Bacarisse 2007-08-22, 7:27 am |
| Jerry Fleming <jerry.fleming@saybot.com> writes:
> Ben Bacarisse wrote On 2007年08月17日 21:16, :
<snip>[vbcol=seagreen]
> No, there are no 13 sub-dir, no is my ls old -- I am working on Ubuntu
> Feisty, which is very new. No mysterious alias, no unknown mounts, no
> anything uncertain, because the system is newly installed.
>
> I tried with other systems (i.e, gentoo linux), and get the same
> confusing result. So I am sure no fsck is needed, but my understanding
> of ls and hard links will have to be reformed 
I would want to know what is going on. Directories always have hard link
counts >1 (on *nix type file systems) and find does not include . and
... in its search so there will always be difference there.
You say, elsewhere, that it is a directory. How may sub-directories
does it have (in other words, how many links are really "missing")?
Many filesystems stop even the super-user from hard-linking
directories, so I'd also want to know what file system type is involved.
For more detailed help, please post the full path name of the
directory in question and the output of 'ls -ld', 'ls -l', 'stat' and
'mount'.
--
Ben.
| |
| Jerry Fleming 2007-08-23, 1:21 am |
| Ben Bacarisse wrote On 2007年08月22日 19:45, :
> Jerry Fleming <jerry.fleming@saybot.com> writes:
>
> <snip>
>
> I would want to know what is going on. Directories always have hard link
> counts >1 (on *nix type file systems) and find does not include . and
> .. in its search so there will always be difference there.
>
> You say, elsewhere, that it is a directory. How may sub-directories
> does it have (in other words, how many links are really "missing")?
> Many filesystems stop even the super-user from hard-linking
> directories, so I'd also want to know what file system type is involved.
>
> For more detailed help, please post the full path name of the
> directory in question and the output of 'ls -ld', 'ls -l', 'stat' and
> 'mount'.
>
Oh, I found there are some hidden directories within myfile, whose
number equals the missing hard links. My god, how can I forget the
hidden files! Thanks everyone for answering my question.
| |
|
| "Jerry Fleming" <jerry.fleming@saybot.com> wrote in message
news:fa3tu5$tjt$1@news.cn99.com...
> Hi,
>
> It's said that the second column of ls -l shows the number of hard links
> to the file. The file under investigation has 15 links. But when I run
> find / -samefile ./myfile -print, it shows only one. After all, I don't
> think that I had created all these hard links, or soft ones. So what
> exactly does the second column mean?
>
> Thanks.
If the entry is a file, it really is the number of links.
In the case of /usr/bin/vi on Solaris 8
$ ls -l /usr/bin/vi
-r-xr-xr-x 5 root bin 207172 Aug 9 2004 /usr/bin/vi
$ ls -il /usr/bin/vi
5565 -r-xr-xr-x 5 root bin 207172 Aug 9 2006
/usr/bin/vi
$ find /usr -inum 6656 2>/dev/null | xargs ls -lid
5565 -r-xr-xr-x 5 root bin 207172 Aug 9 2006
/usr/bin/edit
5565 -r-xr-xr-x 5 root bin 207172 Aug 9 2006
/usr/bin/ex
5565 -r-xr-xr-x 5 root bin 207172 Aug 9 2006
/usr/bin/vedit
5565 -r-xr-xr-x 5 root bin 207172 Aug 9 2006
/usr/bin/vi
5565 -r-xr-xr-x 5 root bin 207172 Aug 9 2006
/usr/bin/view
$
| |
| Stephane CHAZELAS 2007-09-15, 1:19 pm |
| 2007-08-17, 17:47(+08), Jerry Fleming:
[...]
> It's said that the second column of ls -l shows the number of hard links
> to the file. The file under investigation has 15 links. But when I run
> find / -samefile ./myfile -print, it shows only one. After all, I don't
> think that I had created all these hard links, or soft ones. So what
> exactly does the second column mean?
[...]
Maybe the other links are in directories find doesn't have the
permission to access or read.
Or maybe the filesystem has been corrupted at some point and the
other links have been removed without the inode link number
being updated accordingly.
if myfile is a directory, note that "." in it, and ".." in each
of its subdirs will be hard links to in and find won't report
them.
--
Stéphane
| |
| Barry Margolin 2007-09-16, 1:31 am |
| In article <slrnfeo4oe.4is.stephane.chazelas@spam.is.invalid>,
Stephane CHAZELAS <this.address@is.invalid> wrote:
> 2007-08-17, 17:47(+08), Jerry Fleming:
> [...]
> [...]
>
> Maybe the other links are in directories find doesn't have the
> permission to access or read.
Why are people suddenly responding to this month-old thread? The OP
figured out his mistake weeks ago, and it's in the thread.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
|
|
|
|
|