[cs631apue] The confusing output of Linux/GNU ls

Sen Jiang sjiang11 at stevens.edu
Thu Oct 16 23:49:50 EDT 2014


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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.stevens.edu/pipermail/cs631apue/attachments/20141016/5c4b57fe/attachment.html>


More information about the cs631apue mailing list