WEB TUTORIALS
PRACTICE EXAMPLES
HTML REFERENCES
CSS REFERENCES
PHP REFERENCES

How to Make ls Command to Show File Sizes in Megabytes in Ubuntu

Topic: Ubuntu / LinuxPrev|Next

Answer: Use the --block-size Option

If you strictly want ls command to show the file sizes in MB or KB you can use the '--block-size=SIZE' option. It scale file sizes by SIZE before printing them; e.g., --block-size=M prints sizes in units of 1,048,576 bytes. When dealing with memory 1 MB = 1,024 KB = 1,048,576 bytes.

The SIZE argument is an integer and optional unit (for example: 10K is 10*1024). Units are K,M,G,T,P,E,Z,Y (powers of 1024) or KB,MB,... (powers of 1000).

ls -l --block-size=M

The above command however also shows 1M for any file that has size less than 1 MB.

Alternatively, if you simply want to scale the file sizes for readability purpose, rather than specifically showing it in megabytes or gigabytes, you can use the option -h with -l. This will print human readable sizes, i.e., reduce the number of digits to three or less (e.g., 1K, 20M, 5G, etc.).

ls -lh

Related FAQ

Here are some more FAQ related to this topic:

Bootstrap UI Design Templates Property Marvels - A Leading Real Estate Portal for Premium Properties