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--  100K 2005-10-19 11:44 .xsession-errors -rw-------   40K 2005-04-20 11:00 .nessusrc -rwxr--r--   16K 2005-10-12 15:45 .vimrc -rw-------  8.6K 2005-10-19 08:43 .bash_history 


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.

Note

In my ~/.bashrc file, I have the following aliases defined, which have served me well for years. Use what you've learned in this section to extend these examples and create aliases that exactly meet your needs (for more on aliases, see Chapter 11, "Your Shell").

alias l= 'ls -F' alias l1= 'ls -1F' alias la= 'ls -aF' alias ll= 'ls -laFh' alias ls= 'ls -F' 





Linux Phrasebook
Linux Phrasebook
ISBN: 0672328380
EAN: 2147483647
Year: 2007
Pages: 288

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net