LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   less command question (https://www.linuxquestions.org/questions/linux-newbie-8/less-command-question-4175495031/)

sryzdn 02-15-2014 10:58 AM

less command question
 
Hi

When I execute the following command:
Quote:

less /home
I receive:

Quote:

total 28
drwxr-xr-x. 4 root root 4096 Jan 14 11:39 ./
drwxr-xr-x. 18 root root 4096 Feb 15 16:42 ../
drwx------. 2 root root 16384 Jan 14 11:08 lost+found/
drwx------. 35 sryzd sryzdn 4096 Feb 15 17:22 sryzdn/
why can't I see the whole 28 items?

sycamorex 02-15-2014 11:11 AM

Are you sure you did not mean the 'ls' command?

Edit: ok. I see what you mean.

jpollard 02-15-2014 11:45 AM

I believe you are referring to the "total 28" - that is the total files in the directory and subdirectories...

The number can be deceptive, as a directory always has two links, one to itself, and one to its parent, and you have to deduct those... the real confusion is caused by directories that have directories... each of these has a link to its parent directory, which can inflate the count.

michaelk 02-15-2014 11:46 AM

The total is not the number of items but the total number of blocks used by the listed files.
28=4096+4096+16384+4096

The same output can be seen from the output of the ls command (less the parent and self) i.e.
ls -l
or human readable form
ls -lh

sryzdn 02-15-2014 12:10 PM

Quote:

Originally Posted by michaelk (Post 5118248)
The total is not the number of items but the total number of blocks used by the listed files.
28=4096+4096+16384+4096

Please accept my apology if I say I need more explanation on the equation you have mentioned.

jpollard 02-15-2014 12:24 PM

Um...

4096+4096+16384+4096 =28672

if that were a 4k block, 28674/4096 = 7

It would be true if you had a 1K block size... 28672/1024=28

But it doesn't fit my system at all (4k block):

Code:

$ ls -lh /home
total 108K
drwxr-xr-x.  4 root    root    4.0K Jul 11  2010 Fedora
drwx------.  30 hsm    hsm    4.0K Dec 16  2010 hsm
drwxr-xr-x. 120 jesse  family  8.0K Feb 13 01:36 mine
drwxr-xr-x.  2 root    root    48K Oct 31  2008 lost+found
drwxr-xr-x.  75 pam    family  4.0K Jan 17 19:18 another
drwxr-xr-x.  3 root    root    4.0K Jul 15  2010 repository
drwxr-xr-x.  4 root    root    4.0K Dec 23 19:03 sys
drwx------.  22 testing testing 4.0K Jul 14  2012 testing

So unless, I'm looking at something wrong, 4+4+8+48+4+4+4+4=80. not 108

Personally, I think the number is useless.

Found a reference... it is the file size / 1024, not block count. What it does for directory size (which is undefined) is not clear. It also seems to drop "." files...

http://archive.download.redhat.com/p...c/install/ls.c

michaelk 02-15-2014 12:48 PM

What about if you use the -s option...
ls -ls /home

Thanks for the clarification...

jpollard 02-15-2014 01:06 PM

Quote:

Originally Posted by michaelk (Post 5118272)
What about if you use the -s option...
ls -ls /home

In my case, I get the same result as with ls -lh. The block size is reported, but the computation doesn't work. Using the file size/1024 should work... if you can read the directory.

There is some ambiguity, as some filesystems the file length is not normal. The stat(2) man page indicates that the field st_size is the length of regular files and symbolic links. That doesn't work for directories or pipes (either undefined, or invalid). It doesn't work for directories very well because directories on some filesystems may have large holes in the allocation because they use a hash/btree for access speed, thus the block count would indicate a small file, but the file size could indicate a large one. Holes may also occur in regular files in the same way, but they are marked as regular files - and may be copied (a directory can't, when using cp to "copy" a directory, it actually creates a new directory and then copies whatever files are in the original directory to the new directory).

michaelk 02-15-2014 01:09 PM

I expected the same results. Makes sense.


All times are GMT -5. The time now is 10:32 PM.