> ## Content Index
> Fetch the complete content index at: https://itsfoss.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# Check File Size in Linux Command Line
- URL: https://itsfoss.com/linux-check-file-size/
- Published: 2023-10-12T07:29:33.000Z
- Updated: 2023-10-12T07:29:33.000Z
- Description: Learn a thing or two about checking the file size in the Linux command line.
- Author: Abhishek Prakash
- Tags: Terminal, #hide, Quick Tip

How do you check the size of a file in Linux command line? 

The simplest way is to [use the ls command](https://itsfoss.com/ls-command/) with `-lh` option. 

```
ls -lh filename
```

Here's an example:

```
abhishek@itsfoss:~$ ls -lh sample.txt 
-rw-rw-r-- 1 abhishek abhishek 14K Oct 12 11:38 sample.txt
```

As you can see in the example above, the size of the `sample.txt` file is 14K.

Let's see it a bit more in detail.

## Get file size with ls command

The ls command lists the contents of a directory. But with the long listing option `-l`, it shows the file properties as well, file size being one of them.

But by default, the file size is in bytes and it's not easy to understand that. This is why you should combine with the human-readable option `-h`. 

```
ls -lh filename
```

It will start showing file sizes in proper units like KiB, MiB, GiB etc.

In the example below, you can see that the file size was first displayed as 13506 with `-l` option only and 14K with the `-h option.`

![Check file size in Linux with the ls comma](https://itsfoss.com/content/images/2023/10/check-file-size-with-ls-linux-command-1.png)

💡

Did you notice, I used KiB, MiB, GiB, not KB, MB and GB? These days proper binary notation are KiB (=1024 Bytes), MiB (=1024 KiB) and decimal notation are KB (=1000 Bytes), MB (=1000KB). The ls command shows you the classic binary notation.

### The dedicated size option for ls command (but does anyone use it?)

Actually, the ls command has a dedicated option `-s` for showing the file size in blocks. You can combine it with human-readable option `-h` of course.

```
ls -sh filename
```

In this case, it will only show the file size with the filename.

![Check file size in Linux command line with ls command](https://itsfoss.com/content/images/2023/10/check-file-size-with-ls-command.png)

Personally, I have always preferred using the long listing option `-l`. It's more commonly used and I have one less option to remember.

💡

You can display file sizes for more than one file at a time. Just use the ls command on the directory instead of the file name.

### Force ls command to show file size in KB, MB or GB (not recommended)

First, it's not KB, MB or GB but KiB, MiB and GiB. I explained it above.

You can force the ls command to show file size in your favorite unit in this way:

```
ls -l --block-size=M

```

You don't need the human-readable option `-h` anymore.

If you want, GiB, use `--block-size=G`.

There is a major problem with this approach. It works fine for smaller units (file size in GB but you want it in MB) but not for smaller file size and bigger unit. 

In the example below, the sample.txt file of size 16K is shown as 1G if the block-size is changed to G.

![Forcing file sizes in MB or GB have consequences ](https://itsfoss.com/content/images/2023/10/file-size-force-kb-mb-gb-1.png)

Changing the block size is not always a good idea

That's because the ls command calculates the size based on block sizes. Since you defined the minimum unity as 1G, it will show the file size as 1G at the least. 

## What about the directory size?

The ls command cannot (correctly) show you the size of a folder. It always displays as 4K (block size). That's because, technically, a directory is a file that has information on the location of other files in the memory.

![ls command cannot show directory size](https://itsfoss.com/content/images/2023/10/ls-directory-size-1.png)

To get the directory size, you use the du command (disk utilization) in the following way:

```
du -sh dirname
```

![Get directory size in Linux](https://itsfoss.com/content/images/2023/10/get-directory-size-linux.png)

You may also use the stat command to get the file size but somehow I feel more comfortable using the ls command.

I hope this basic Linux command tip helped you check file sizes in Linux.