Home > Articles > Operating Systems, Server > Linux/UNIX/Open Source

  • Print
  • + Share This
This chapter is from the book

This chapter is from the book

Express File Sizes in Terms of K, M, and G

ls -h

In the previous section, the 15465 on .vimrc’s line means that the file is about 15KB, but it’s not always convenient to mentally translate bytes into the equivalent kilobytes, megabytes, or gigabytes. Most of the time, it’s more convenient to use the -h option (or --human-readable), which makes things easier to understand.

$ ls -laSh ~/
-rw-r--r--    1 scott scott 100K 2015-10-19 11:44 .xsession-errors
-rw-------    1 scott scott  40K 2015-04-20 11:00 .nessusrc
-rw-r--r--    1 scott scott  25K 2015-04-20 11:00 .abbrev_defs
-rwxr--r--    1 scott scott  16K 2015-10-12 15:45 .vimrc
-rw-------    1 scott scott  12K 2015-10-19 10:59 .viminfo
-rw-------    1 scott scott 8.6K 2015-10-19 08:43 .bash_history
[List condensed and edited due to length]

In this example, you see K for kilobytes; if the files were big enough, you’d see M for megabytes or even G for gigabytes. Some of you might be wondering how 40122 bytes for .nessusrc became 40K when you used -h. Remember that 1024 bytes make up a kilobyte, so when you divide 40122 by 1024, you get 39.1816406 kilobytes, which ls -h rounds up to 40K. A megabyte is actually 1,048,576 bytes, and a gigabyte is 1,073,741,824 bytes, so a similar sort of rounding takes place with those as well. If you want exact powers of ten in your divisions (that is, what are referred to as “kibibytes,” “mebibytes,” and so on—see Chapter 6, “Viewing (Mostly Text) Files,” for more), try the --si option.

  • + Share This
  • 🔖 Save To Your Account