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
Abhishek Prakash

Table of Contents

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.

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

ls -lh

As you can see, it is better to display file size in 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 size less than 1 MB will also be displayed with file size 1 MB.

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:

[email protected]:~/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
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.



Join the conversation.