[cs631apue] The confusing output of Linux/GNU ls

Sen Jiang sjiang11 at stevens.edu
Fri Oct 17 00:21:55 EDT 2014


Like I said, you need to use st_blocks*512 instead of st_size for each file.
To count total blocks, you should add all st_blocks first, and then convert
to units of 512 or BLOCKSIZE.

On Fri, Oct 17, 2014 at 12:11 AM, zding4 <zding4 at stevens.edu> wrote:

> In the long format part of ls.pdf
>
> In addition, for each directory whose contents are displayed, the total
> number of blocks in units of 512 bytes
> or BLOCKSIZE (see ENVIRONMENT)used by the files in the directory is
> displayed on a line by itself
> immediately before the information for the files in the directory.
>
> What I ask is the how to count the number of file system blocks actually
> used by each file in units of 512 bytes or
> BLOCKSIZE (see ENVIRONMENT) (-s, -l total)
>
>
> 在 10/16/2014 11:49 PM,Sen Jiang 写道:
>
>> Blocks should be calculated using st_blocks*512, not st_size.
>>
>> According to ls.pdf:
>>
>>  a total sum for all the file sizes is output on a line before the
>>> listing.
>>>
>>
>> We need to print sum of file sizes instead of number of blocks, not
>> sure if it's typo.
>>
>> On Thu, Oct 16, 2014 at 10:15 PM, zding4 <zding4 at stevens.edu> wrote:
>>
>>  I find some very confusing output of Linux ls when I play it.
>>>
>>> here is the output
>>>
>>> zding4 at avatar:~/apue/midterm$ ls -ls
>>> total 52
>>>  1 -rw-r--r--+ 1 zding4 student    37 Oct 13 21:33 Makefile
>>> 21 -rwxr-xr-x+ 1 zding4 student 20060 Oct 16 20:02 a.out
>>>  3 -rw-r--r--+ 1 zding4 student  1634 Oct 16 20:04 alink
>>>  3 -rw-r--r--+ 1 zding4 student  1173 Oct 13 14:30 chldlist.c
>>>  1 -rw-r--r--+ 1 zding4 student     0 Oct 14 15:24
>>> dfsf?????????bla.txt
>>>  2 drwxr-xr-x+ 2 zding4 student     2 Oct 16 19:20 empty
>>>  3 -rw-r--r--+ 1 zding4 student  1598 Oct 16 20:04 file2
>>>  2 -rw-r--r--+ 1 zding4 student   748 Oct 12 22:44 l.h
>>> 17 -rw-r--r--+ 1 zding4 student 11408 Oct 16 20:25 ls.c
>>>  1 -rw-r--r--+ 1 zding4 student     0 Oct 13 21:47 out
>>>  1 lrwxrwxrwx  1 zding4 student     5 Oct 16 20:12 slink ->
>>> file1
>>>  2 d-wx--x--x+ 3 zding4 student     3 Oct 16 18:48 test
>>>
>>> first is that
>>> 1+21+3+3+1+2+3+2+17+1+1+2 != 52
>>>
>>> The size of test directory is only 3 but it takes 2 blocks
>>>
>>> Any idea why this happen?
>>>
>>> When I implement ls,
>>> The block number is `st_size/BLOCKSIZE`
>>> And the total is the sum of files' block number.
>>>
>>> _______________________________________________
>>> cs631apue mailing list
>>> cs631apue at lists.stevens.edu
>>> https://lists.stevens.edu/mailman/listinfo/cs631apue [1]
>>>
>>
>>
>>
>> Links:
>> ------
>> [1] https://lists.stevens.edu/mailman/listinfo/cs631apue
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.stevens.edu/pipermail/cs631apue/attachments/20141017/05b6e5cc/attachment-0001.html>


More information about the cs631apue mailing list