Computer Science Atlas

Ubuntu: Check File Size

January 31, 2021
Table of Contents


This tutorial explains how to show the size of individual files on Ubuntu.

To find out how much disk space an entire directory uses (including all of its subdirectories), see this tutorial.

To find out the total disk space usage by an entire disk volume, see this tutorial.

Step 1. Open a Terminal Session

If you're using an Ubuntu laptop or desktop, you can press Ctrl + Alt + T on your keyboard to open a new terminal window. If you're using a remote Ubuntu server, you can connect using SSH to open a new terminal session.

Step 2. Use ls

All Files in Current Directory Except Hidden Files

If you want to see the file sizes of every file in the current directory:

ls -l -h
$ ls -l -h

You should see output like:

total 412K
-rw-r----- 1 ubuntu ubuntu 255K Jan 31 22:40 page1.html
-rw-r--r-- 1 ubuntu ubuntu 140K Jan 31 22:40 page2.html
-rw-rw-r-- 1 ubuntu ubuntu 286K Jan 31 22:40 page3.html

The fifth column of the output shows the file size (e.g., 255K, 140K and 286K in the output above).

The -l option tells ls to show various metadata about the file, including file size. Without this option, ls only shows filenames.

The -h option tells ls to show human-friendly units such as M for megabytes, G for gigabytes, etc.

As usual, you can combine the options and get the same output:

ls -lh
$ ls -lh

Show Hidden Files

To include hidden files (files whose filenames start with . such as .gitignore), add the -a option:

ls -a -l -h
$ ls -a -l -h

or, combined:

ls -alh
$ ls -alh

Specific Files

To show the file size of a specific file called page1.html in the current directory, you can run:

ls -lh page1.html
$ ls -lh page1.html

You can also list multiple specific files:

ls -lh page1.html page2.html
$ ls -lh page1.html page2.html

Other Directories

If you want to show output for directories other than the current directory, you can include their paths at the end of the command. For example, to show the file size of all files (including hidden) in the directory website inside the home directory, you can run:

ls -alh ~/website
$ ls -alh ~/website