Operating System - HP-UX
1752794 Members
6050 Online
108789 Solutions
New Discussion юеВ

Re: one simple query regarding ls -lrt output

 
SOLVED
Go to solution
Amit Jindal_1
Frequent Advisor

Re: one simple query regarding ls -lrt output

Thanks Avinsh, but can you give the example with ls -lart showing the . and .. field link counts.

with normal files I am able to understand the ln counts but not with respect to the numbers against "." and ".."
Avinash20
Honored Contributor

Re: one simple query regarding ls -lrt output

Hi,

Please refer to

http://forums11.itrc.hp.com/service/forums/questionanswer.do?threadId=1046949

See the last two post and the explanation by Bill for the same
"Light travels faster than sound. That's why some people appear bright until you hear them speak."
Heironimus
Honored Contributor

Re: one simple query regarding ls -lrt output

The explanation of a directory's link count is a little complex, but only a little. "." and ".." really exist in the filesystem as links. When you create the directory /tmp/foo you get one link for "/tmp/foo" and one link for "." (actually "/tmp/foo/."). That means that an empty directory starts out with two links. Every directory you create inside /tmp/foo will have a ".." link pointing back to /tmp/foo, which increases its link count by one.

This means that the link count for any directory will be the number of directories it contains plus two, and the link count for ".." is just the parent directory's link count.
Dennis Handly
Acclaimed Contributor
Solution

Re: one simple query regarding ls -lrt output

drwxr-xr-x 2771 root root ..
drwxr-xr-x 3 user1 users .

This says there are 2771 users (directories) under /home.
And there are 2 directories in user1 and the reference in /home.
Dennis Handly
Acclaimed Contributor

Re: one simple query regarding ls -lrt output

>ME: And there are 2 directories in user1 and the reference in /home.

Oops, off by one, see Heironimus' reply.
щ╗ЮчЗГ
Valued Contributor

Re: one simple query regarding ls -lrt output

Every directory will have two links by default. ('.' and '..').Whenever a directory is getting created, the link count of the parent directory will increase by one.
Eg:-
In the following output the link count of /test is 9, since there are 7 directories in it and plus two. (current and parent directories.)
# ls -lart |grep -i test
drwxr-xr-x 9 root sys 8192 Mar 4 01:15 test


# cd /test
# ls -lart
total 32
drwxr-xr-x 28 root root 8192 Mar 4 01:12 ..
-rw-r--r-- 1 root sys 0 Mar 4 01:12 abc.txt
drwxr-xr-x 2 root sys 96 Mar 4 01:13 b
drwxr-xr-x 3 root sys 96 Mar 4 01:14 abc
drwxr-xr-x 2 root sys 96 Mar 4 01:15 4
drwxr-xr-x 9 root sys 8192 Mar 4 01:15 .
drwxr-xr-x 2 root sys 96 Mar 4 01:15 2
drwxr-xr-x 2 root sys 96 Mar 4 01:15 3
drwxr-xr-x 2 root sys 96 Mar 4 01:15 1
drwxr-xr-x 2 root sys 96 Mar 4 01:15 5


# ls -lart |grep -i "^d" |wc -l
9


---------------------------------------------
Man's mind, once stretched by a new idea, never regains its original dimensions
Amit Jindal_1
Frequent Advisor

Re: one simple query regarding ls -lrt output

Thanks to all .. particularly to Dennis and Pradeesh who are spot on ...

Thanks for your time ..i have given the points ..