Managing disk space is a critical skill for any Linux user. Whether you are cleaning up a server or managing personal documents, you often need to check file size in Ubuntu terminal to see what is taking up space.
Fortunately, Linux provides several built-in commands to help you verify file and directory sizes quickly. Here are the 4 best methods to check file size in Ubuntu terminal.
Here is a quick summary table of the commands covered in the article.
Table of Contents
Quick Cheat Sheet: Checking File Sizes in Ubuntu
| Command | Syntax / Example | Best Used For | Output Format |
|---|---|---|---|
ls | ls -lh filename | Quickly checking a single file in a list | Human-readable (KB, MB, GB) |
du | du -sh foldername | Checking total size of a directory | Summary total (e.g., 500M) |
stat | stat filename | Getting exact byte count & metadata | Raw bytes, blocks, & dates |
ncdu | ncdu | Analyzing disk usage to free up space | Interactive / Visual UI |
sort | ls -lhS | Sorting files by size (largest first) | Sorted list |
1. Use the ls Command (Best for Single Files)
The most common way to check file size in Ubuntu terminal is using the ls (list) command. By default, ls only shows filenames, but adding flags gives you detailed size information.
Command:
ls -lh filename.txt
Explanation:
-l(Long listing): Displays permissions, owner, date, and size.-h(Human-readable): Converts bytes into easy-to-read formats like KB, MB, or GB.
Output Example:
-rw-r--r-- 1 user user 5.0M Mar 10 10:00 video.mp4
(The file size is clearly shown as 5.0M).
2. Use the du Command (Best for Directories)
While ls is great for individual files, the du (Disk Usage) command is the best tool to check file size in Ubuntu terminal for both files and entire directories.
Command:
See also: Mastering the Linux Command Line — Your Complete Free Training Guide
du -h filename.txt
To check a specific folder size:
du -sh /path/to/directory
Explanation:
-s(Summary): Shows the total size of the folder instead of listing every single file inside it.-h: Displays the size in Human-readable format (K, M, G).
3. Use the stat Command (Best for Precision)
If you need to know the exact byte count of a file, stat is the most precise tool available. It displays detailed metadata about the file.
Command:
stat filename.txt
Output Example:
File: video.mp4
Size: 5242880 Blocks: 10240 IO Block: 4096 regular file
This is useful for scripts or when verifying if a file transfer was completed exactly.
4. Use ncdu (Best Visual Tool)
If you want to check file size in Ubuntu terminal interactively to clean up disk space, ncdu is an excellent visual tool. You may need to install it first.
Installation:
sudo apt install ncdu
Usage:
ncdu
This opens a graphical interface inside your terminal, allowing you to navigate folders and see which files are the largest, sorted automatically by size.
FAQ: Quick Answers about File Sizes
Here are 5 common questions on how to check file size in Ubuntu terminal.
- How do I check the total size of a directory?
Rundu -sh foldernameto see the total summary in MB or GB. - How do I list all files sorted by size?
Runls -lhS(the capitalSflag sorts files from largest to smallest). - How do I check the size of a file in bytes only?
Runwc -c filenameto output just the byte count. - Does
lsshow hidden file sizes?
No, you must add the-aflag:ls -lahto see hidden files and their sizes. - How do I find the top 5 largest files?
Rundu -ah | sort -rh | head -n 5to list the biggest files in the current folder.




