Skip to main content
Quick Tip

How to Display File Size in Human Readable Format (KB, MB, GB) in Linux Terminal

Quick tip to display file size in Linux using the ls command.

β€” Abhishek Prakash

Warp Terminal

You probably already know that you can use ls command with long listing option -l to show file size in Linux.

ls -l

But unfortunately, the long listing shows the file size in blocks and that's not of much use to us humans.

The good thing is that you can combine the option -l with -h to show the file size in a human-readable format.

ls -lh

As you can see, it is better to display file size in a human-readable format.

As you can see, file sizes are now displayed in K (for KB), M for (MB). If the file size is in Bytes, it is not displayed with any suffix. In the above example, char.sh is 140 Bytes in size.

Did you notice the size of new_dir directory? It is 4 KB. If you use ls -lh command on directories, it always shows the size of directory as 4.0 K.

You'll have to use du command to get the real size of a directory in Linux.

How to Find Size of Directory with du Command in Linux
The du command in Linux is used for checking the size of directory. Here are various ways you can find the size of directory in Linux with the du command.

By default, the block size in most Linux system is 4096 Bytes or 4 KB. A directory in Linux is simply a file with the information about the memory location of all the files in it.

You can force ls command to display file size in MB with the --block-size flag.

ls -l --block-size=M

The problem with this approach is that all the files with a size of less than 1 MB will also be displayed with file size of 1 MB.

Learn Linux Quickly - Linux Commands for Beginners
Learn Linux Quickly doesn’t assume any prior Linux knowledge, which makes it a perfect fit for beginners. Nevertheless, intermediate and advanced Linux users will still find this book very useful as it goes through a wide range of topics. Learn Linux Quickly will teach you the following topics:Insta…

The ls command also has -s option to display size. You should combine with -h to show the file size in human readable form.

ls -sh

Here's the output:

abhishek@handbook:~/tutorial$ ls -sh
total 324M
4.0K char.sh      4.0K hello.sh              319M wp_ghost_export.zip
4.0K file.txt     4.0K new_dir
4.0K filetype.sh  5.5M wp_ghost_export.json

You can use the -S option of the ls command to sort files by size. This is also helpful in knowing which files take the most space on your system.

How to Find the 10 Biggest Files in Linux Command Line
Quick tutorial to show you how to find the biggest files on your Linux machine using a few commands that you may already be familiar with du, sort, and head.

You can also use the stat command in Linux to check the file size.

stat filename

I hope you find this quick tip helpful in seeing the file size in Linux.

Abhishek Prakash