LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-15-2014, 10:58 AM   #1
sryzdn
Member
 
Registered: Feb 2013
Posts: 266

Rep: Reputation: 9
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?
 
Old 02-15-2014, 11:11 AM   #2
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,819
Blog Entries: 1

Rep: Reputation: 1209Reputation: 1209Reputation: 1209Reputation: 1209Reputation: 1209Reputation: 1209Reputation: 1209Reputation: 1209Reputation: 1209
Are you sure you did not mean the 'ls' command?

Edit: ok. I see what you mean.

Last edited by sycamorex; 02-15-2014 at 11:12 AM.
 
Old 02-15-2014, 11:45 AM   #3
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,688

Rep: Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259
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.
 
Old 02-15-2014, 11:46 AM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 15,716

Rep: Reputation: 1751Reputation: 1751Reputation: 1751Reputation: 1751Reputation: 1751Reputation: 1751Reputation: 1751Reputation: 1751Reputation: 1751Reputation: 1751Reputation: 1751
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

Last edited by michaelk; 02-15-2014 at 11:51 AM.
 
Old 02-15-2014, 12:10 PM   #5
sryzdn
Member
 
Registered: Feb 2013
Posts: 266

Original Poster
Rep: Reputation: 9
Quote:
Originally Posted by michaelk View Post
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.
 
Old 02-15-2014, 12:24 PM   #6
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,688

Rep: Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259
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

Last edited by jpollard; 02-15-2014 at 12:47 PM.
 
1 members found this post helpful.
Old 02-15-2014, 12:48 PM   #7
michaelk
Moderator
 
Registered: Aug 2002
Posts: 15,716

Rep: Reputation: 1751Reputation: 1751Reputation: 1751Reputation: 1751Reputation: 1751Reputation: 1751Reputation: 1751Reputation: 1751Reputation: 1751Reputation: 1751Reputation: 1751
What about if you use the -s option...
ls -ls /home

Thanks for the clarification...

Last edited by michaelk; 02-15-2014 at 01:02 PM.
 
Old 02-15-2014, 01:06 PM   #8
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,688

Rep: Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259
Quote:
Originally Posted by michaelk View Post
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).
 
1 members found this post helpful.
Old 02-15-2014, 01:09 PM   #9
michaelk
Moderator
 
Registered: Aug 2002
Posts: 15,716

Rep: Reputation: 1751Reputation: 1751Reputation: 1751Reputation: 1751Reputation: 1751Reputation: 1751Reputation: 1751Reputation: 1751Reputation: 1751Reputation: 1751Reputation: 1751
I expected the same results. Makes sense.
 
  


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
ps command question MarkoSan Linux - Newbie 8 02-22-2013 12:00 AM
Question about command dd miros84 Linux - Software 7 02-10-2010 04:09 PM
dd command question cdestiny Linux - General 1 02-24-2009 05:08 AM
A question concerning the 'dd'-command Nyx Linux - Newbie 9 02-04-2007 08:03 AM
cp command question Freestone Linux - Newbie 4 05-01-2006 09:39 AM


All times are GMT -5. The time now is 06:09 AM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration