Search code examples
fileunixusability

Format file size in Unix in readable format


When I do ls -l I get

-rw-r--r--   1 jboss    admin  **26644936** Sep  1 21:23 MyBig.war

How do I print it as below

-rw-r--r--   1 jboss    admin  **26,644,936** Sep  1 21:23 MyBig.war

Solution

  • The proper way to format ls output is to specify BLOCK_SIZE.

    Saying:

    BLOCK_SIZE="'1" ls -l
    

    would achieve your desired result.

    Quoting from the above link:

    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.


    A block size specification preceded by ‘'’ causes output sizes to be displayed with thousands separators.