Q:

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

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this 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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now