coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: suggestion for 'ls' coreutil, comma'd filesizes in -l output


From: Bob Proulx
Subject: Re: suggestion for 'ls' coreutil, comma'd filesizes in -l output
Date: Tue, 4 Jun 2013 14:24:07 -0600
User-agent: Mutt/1.5.21 (2010-09-15)

smu johnson wrote:
> I have a suggestion for 'ls'.  My idea is a GNU extension switch which
> commafies (for lack of a better word) the filesizes in the basic -l output
> of integers.  This has been the default for 'dir' since MS-DOS, but I think
> it might be a good addition for an optional switch in 'ls', in which case
> i'd "enable it" by making / modifying my alias for 'ls'.
> 
> Right now I use a frontend for 'ls' written in Perl to do the same job, but
> as you can probably guess, the solution is a bit cludgey and likely prone
> to fail down the road.  But right now, its output is:
> 
> address@hidden:/tmp/sjohnson$ ls -l test*
> -rw-r--r-- 1 sjohnson sjohnson    13,824 2012-12-10 13:32 test1.txt
> -rw-r--r-- 1 sjohnson sjohnson     9,973 2012-12-10 12:13 test.bin
> -rw-r--r-- 1 sjohnson sjohnson        71 2013-04-10 17:49 test.txt

See the GNU coreutils ls documentation.  I will reproduce it here but
you can jump directly to the specific documentation node this way:

  $ info coreutils 'Block size'

Try this:

  $ ls -l --block-size="'1kB"

And you can always set

  export LS_BLOCK_SIZE="'1kB"

in your environment to have that by default all of the time for ls.

Bob

  $ info coreutils 'Block size'

2.3 Block size
==============

Some GNU programs (at least `df', `du', and `ls') display sizes in
"blocks".  You can adjust the block size and method of display to make
sizes easier to read.  The block size used for display is independent
of any file system block size.  Fractional block counts are rounded up
to the nearest integer.

   The default block size is chosen by examining the following
environment variables in turn; the first one that is set determines the
block size.

`DF_BLOCK_SIZE'
     This specifies the default block size for the `df' command.
     Similarly, `DU_BLOCK_SIZE' specifies the default for `du' and
     `LS_BLOCK_SIZE' for `ls'.

`BLOCK_SIZE'
     This specifies the default block size for all three commands, if
     the above command-specific environment variables are not set.

`BLOCKSIZE'
     This specifies the default block size for all values that are
     normally printed as blocks, if neither `BLOCK_SIZE' nor the above
     command-specific environment variables are set.  Unlike the other
     environment variables, `BLOCKSIZE' does not affect values that are
     normally printed as byte counts, e.g., the file sizes contained in
     `ls -l' output.

`POSIXLY_CORRECT'
     If neither `COMMAND_BLOCK_SIZE', nor `BLOCK_SIZE', nor `BLOCKSIZE'
     is set, but this variable is set, the block size defaults to 512.


   If none of the above environment variables are set, the block size
currently defaults to 1024 bytes in most contexts, but this number may
change in the future.  For `ls' file sizes, the block size defaults to
1 byte.

   A block size specification can be a positive integer specifying the
number of bytes per block, or it can be `human-readable' or `si' to
select a human-readable format.  Integers may be followed by suffixes
that are upward compatible with the SI prefixes
(http://www.bipm.org/en/si/si_brochure/chapter3/prefixes.html) for
decimal multiples and with the ISO/IEC 80000-13 (formerly IEC 60027-2)
prefixes (http://physics.nist.gov/cuu/Units/binary.html) for binary
multiples.

   With human-readable formats, output sizes are followed by a size
letter such as `M' for megabytes.  `BLOCK_SIZE=human-readable' uses
powers of 1024; `M' stands for 1,048,576 bytes.  `BLOCK_SIZE=si' is
similar, but uses powers of 1000 and appends `B'; `MB' stands for
1,000,000 bytes.

   A block size specification preceded by `'' causes output sizes to be
displayed with thousands separators.  The `LC_NUMERIC' locale specifies
the thousands separator and grouping.  For example, in an American
English locale, `--block-size="'1kB"' would cause a size of 1234000
bytes to be displayed as `1,234'.  In the default C locale, there is no
thousands separator so a leading `'' has no effect.

   An integer block size can be followed by a suffix to specify a
multiple of that size.  A bare size letter, or one followed by `iB',
specifies a multiple using powers of 1024.  A size letter followed by
`B' specifies powers of 1000 instead.  For example, `1M' and `1MiB' are
equivalent to `1048576', whereas `1MB' is equivalent to `1000000'.

   A plain suffix without a preceding integer acts as if `1' were
prepended, except that it causes a size indication to be appended to
the output.  For example, `--block-size="kB"' displays 3000 as `3kB'.

   The following suffixes are defined.  Large sizes like `1Y' may be
rejected by your computer due to limitations of its arithmetic.

`kB'
     kilobyte: 10^3 = 1000.

`k'
`K'
`KiB'
     kibibyte: 2^10 = 1024.  `K' is special: the SI prefix is `k' and
     the ISO/IEC 80000-13 prefix is `Ki', but tradition and POSIX use
     `k' to mean `KiB'.

`MB'
     megabyte: 10^6 = 1,000,000.

`M'
`MiB'
     mebibyte: 2^20 = 1,048,576.

`GB'
     gigabyte: 10^9 = 1,000,000,000.

`G'
`GiB'
     gibibyte: 2^30 = 1,073,741,824.

`TB'
     terabyte:  10^12 = 1,000,000,000,000.

`T'
`TiB'
     tebibyte: 2^40 = 1,099,511,627,776.

`PB'
     petabyte: 10^15 = 1,000,000,000,000,000.

`P'
`PiB'
     pebibyte: 2^50 = 1,125,899,906,842,624.

`EB'
     exabyte: 10^18 = 1,000,000,000,000,000,000.

`E'
`EiB'
     exbibyte: 2^60 = 1,152,921,504,606,846,976.

`ZB'
     zettabyte: 10^21 = 1,000,000,000,000,000,000,000

`Z'
`ZiB'
     2^70 = 1,180,591,620,717,411,303,424.

`YB'
     yottabyte: 10^24 = 1,000,000,000,000,000,000,000,000.

`Y'
`YiB'
     2^80 = 1,208,925,819,614,629,174,706,176.

   Block size defaults can be overridden by an explicit
`--block-size=SIZE' option.  The `-k' option is equivalent to
`--block-size=1K', which is the default unless the `POSIXLY_CORRECT'
environment variable is set.  The `-h' or `--human-readable' option is
equivalent to `--block-size=human-readable'.  The `--si' option is
equivalent to `--block-size=si'.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]