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.
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.
If you want to see the file sizes of every file in the current directory:
$ 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.,
286K in the output above).
-l option tells
ls to show various metadata about the file, including file size. Without this option,
ls only shows filenames.
-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
To include hidden files (files whose filenames start with
. such as
.gitignore), add the
$ ls -a -l -h
$ ls -alh
To show the file size of a specific file called
page1.html in the current directory, you can run:
$ ls -lh page1.html
You can also list multiple specific files:
$ ls -lh page1.html page2.html
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