[cs631apue] [cs631] Questions about the -h flag and -l and -1

Jan Schaumann jschauma at stevens.edu
Thu Oct 4 13:44:00 EDT 2012


tparisi <tparisi at stevens.edu> wrote:

> 1. When utilizing the -h flag, the real ls sometimes rounds and  
> sometimes displays decimal sizes.  For instance, the size 8582 yields an  
> output of 8.4K when it is divided by 1024.  However when 13736 is  
> divided by 1024 it yields an answer of 14K when in actuality it yields  
> an answer of 13.4.  My question is, is it enough for us to only up the  
> size when using the -k and -h flags?

Take a look at the humanize_number(3) function.  Using that is likely
sufficient for you to not have to worry about that.

> 2.  The -l(elle) and -1(one) override each other.  Does this mean that  
> the -l(elle) flag means the infomation for the files is to not be  
> printed one per line because I see no mention one long listing per file  
> per line in the man page.  But the default of the ls is to be one entry  
> per line to standard output, so the -1(one) flag can effectively be  
> ignored if everything is to be printed to one line regardless if it is  
> to a file or to the terminal.

In your version, '-1' is the default.  However, it is possible to give
conflicting options on the command-line:

ls -l -1 -l -1 -1 -1 -l -l -1 -l

For any conflicting options, the last one takes precedence.

But yes, the distinction of whether or not output is to a terminal or
not is, irrelevant, unless you choose to implement the '-c' option for
extra credit.

-Jan


More information about the cs631apue mailing list