System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

one simple query regarding ls -lrt output

SOLVED
Go to solution
Amit Jindal_1
Frequent Advisor

one simple query regarding ls -lrt output

Hi HP UX Gurus . ..
I have got a question regarding the ls -lrt output. Feeling a bit embarrassed to raise this kiddie type question ... who cares! my boss don't have a id in this forum..

$ pwd
/home/user1

$ ls -lart
total 2566
-rw-r--r-- 1 user1 users 362 Apr 15 2003 .kshrc
-rw-r--r-- 1 user1 users 636 Apr 15 2003 .login
-rw-r--r-- 1 user1 users 535 Apr 15 2003 .profile
-rw-r--r-- 1 user1 users 591 Apr 15 2003 .cshrc
-rwxr-xr-x 1 user1 users 24576 Jan 26 2004 a.out
-rwxr-xr-x 1 user1 users 629 Sep 21 2005 spacevg
-rwxr-xr-x 1 user1 users 197 Nov 11 2005 final
drwxr-xr-x 2771 root root 48128 Jun 20 2006 ..
drwxr-xr-x 4 user1 users 96 Jan 15 2007 perf
-rw------- 1 user1 users 34506 Nov 13 11:13 .gpmhp-host1
-r-xr-xr-x 1 user1 users 1188080 Mar 7 11:08 tcpdump
-rwxr-xr-x 1 user1 users 149 Mar 19 17:36 .history
drwxr-xr-x 3 user1 users 1024 Mar 20 09:24 .
-rw------- 1 user1 users 2694 Mar 20 09:26 .sh_history

$ du -sk .
1244 .

$ df -g .
/home (/dev/vg00/lvol_home ) :
8192 file system block size 1024 fragment size
212992 total blocks 596 total free blocks
596 allocated free blocks 22912 total i-nodes
386 total free i-nodes 386 allocated free i-nodes
1073741835 file system id vxfs file system type
0 flags 255 file system name length
/home file system specific string
$

#########################

1) What is the first line from the output of ls -lrt signifies ? I read somewhere that it is total number of blocks used. Can I somehow map the no of the blocks to the du -sk output.

2)The second column of the output is the link count to that file, so against . and .. the values are 3 and 2771 respectively. What does that means ? I guess.. is my home dir /home/user1 is being referred from 2 other locations ?
16 REPLIES
Avinash20
Honored Contributor

Re: one simple query regarding ls -lrt output

1) What is the first line from the output of ls -lrt signifies ? I read somewhere that it is total number of blocks used. Can I somehow map the no of the blocks to the du -sk output.

## It signifies number of files
"Light travels faster than sound. That's why some people appear bright until you hear them speak."
Avinash20
Honored Contributor

Re: one simple query regarding ls -lrt output

Sorry.. Ignore my above post !!
"Light travels faster than sound. That's why some people appear bright until you hear them speak."
Amit Jindal_1
Frequent Advisor

Re: one simple query regarding ls -lrt output

But how can it be the number of files ?? I have done a ls -lart and there are 12 files. Then it should be 12 not 2566.

Avinash20
Honored Contributor

Re: one simple query regarding ls -lrt output

Answer 1>

When an option is specified that results in a listing of directory and/or file sizes in bytes or blocks (such as the -s or -l (ell) option), a total count of blocks, including indirect blocks, is also printed at the beginning of the listing.
"Light travels faster than sound. That's why some people appear bright until you hear them speak."
Avinash20
Honored Contributor

Re: one simple query regarding ls -lrt output

The second column of the output is the hard link count
"Light travels faster than sound. That's why some people appear bright until you hear them speak."
Avinash20
Honored Contributor

Re: one simple query regarding ls -lrt output

You could find the link file via

find / -linkedto
"Light travels faster than sound. That's why some people appear bright until you hear them speak."
Amit Jindal_1
Frequent Advisor

Re: one simple query regarding ls -lrt output

I know the second column is the hard link count.


drwxr-xr-x 2771 root root 48128 Jun 20 2006 ..
drwxr-xr-x 3 user1 users 1024 Mar 20 09:24 .

Against . the ln count is 3 and against .. it is 2771, What are these numbers ? how can i verify it ? The hard link is not there for folders then who is referring to the home dir ? I have checked the ls -li output for inode numbers, but no answers ..

Avinash20
Honored Contributor

Re: one simple query regarding ls -lrt output

shivaji@root/tmp/test1>ll
total 32
-rw-rw-rw- 1 root sys 8 Mar 3 20:45 a
-rw-rw-rw- 1 root sys 19 Mar 3 20:46 b
shivaji@root/tmp/test1>find / -linkedto a
/tmp/test1/a
shivaji@root/tmp/test1>
shivaji@root/tmp/test1>
shivaji@root/tmp/test1>ln -s a c
shivaji@root/tmp/test1>ll
total 32
-rw-rw-rw- 1 root sys 8 Mar 3 20:45 a
-rw-rw-rw- 1 root sys 19 Mar 3 20:46 b
lrwxrwxrwx 1 root sys 1 Mar 3 20:59 c -> a
shivaji@root/tmp/test1>find / -linkedto a
/tmp/test1/a
shivaji@root/tmp/test1>find /tmp/test1 -linkedto a
/tmp/test1/a
shivaji@root/tmp/test1>ll
total 32
-rw-rw-rw- 1 root sys 8 Mar 3 20:45 a
-rw-rw-rw- 1 root sys 19 Mar 3 20:46 b
lrwxrwxrwx 1 root sys 1 Mar 3 20:59 c -> a
shivaji@root/tmp/test1>find / -linkedto c
/tmp/test1/c
shivaji@root/tmp/test1>ln a d
shivaji@root/tmp/test1>ll
total 48
-rw-rw-rw- 2 root sys 8 Mar 3 20:45 a
-rw-rw-rw- 1 root sys 19 Mar 3 20:46 b
lrwxrwxrwx 1 root sys 1 Mar 3 20:59 c -> a
-rw-rw-rw- 2 root sys 8 Mar 3 20:45 d


AS suggested earlier, you could verify it via

# find / -linkedto
"Light travels faster than sound. That's why some people appear bright until you hear them speak."
Avinash20
Honored Contributor

Re: one simple query regarding ls -lrt output

For directories
drwxr-xr-x 2771 root root 48128 Jun 20 2006 ..
drwxr-xr-x 3 user1 users 1024 Mar 20 09:24 .

Let me check
"Light travels faster than sound. That's why some people appear bright until you hear them speak."
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 ..