How To Check File Size in Linux

How To Check File Size in Linux

h2 {
font-size: 28px;
font-weight: 600;
color: #0a0a0a;
margin-top: 40px;
margin-bottom: 20px;
letter-spacing: -0.5px;
}

h3 {
font-size: 22px;
font-weight: 600;
color: #1a1a1a;
margin-top: 32px;
margin-bottom: 16px;
letter-spacing: -0.3px;
}

h4 {
font-size: 18px;
font-weight: 500;
color: #2a2a2a;
margin-top: 24px;
margin-bottom: 14px;
}

a {
color: #1a73e8;
text-decoration: none;
transition: color 0.2s ease;
}

a:hover {
color: #1557b0;
text-decoration: underline;
}

code {
background-color: #f5f5f5;
padding: 2px 6px;
border-radius: 3px;
font-family: ‘Courier New’, monospace;
font-size: 14px;
color: #d63384;
}

pre {
background-color: #f8f9fa;
padding: 16px;
border-radius: 6px;
overflow-x: auto;
margin: 20px 0;
border-left: 4px solid #1a73e8;
}

pre code {
background-color: transparent;
padding: 0;
color: #1a1a1a;
}

table {
width: 100%;
border-collapse: collapse;
margin: 24px 0;
font-size: 15px;
}

table th {
background-color: #f8f9fa;
padding: 12px;
text-align: left;
font-weight: 600;
border-bottom: 2px solid #dee2e6;
}

table td {
padding: 12px;
border-bottom: 1px solid #dee2e6;
}

details {
background-color: #f8f9fa;
border: 1px solid #e0e0e0;
border-radius: 8px;
margin-bottom: 12px;
overflow: hidden;
transition: all 0.3s ease;
}

details:hover {
background-color: #f5f5f5;
}

details[open] {
background-color: #ffffff;
box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

summary {
padding: 18px 20px;
cursor: pointer;
font-weight: 500;
font-size: 16px;
color: #1a1a1a;
list-style: none;
display: flex;
align-items: center;
justify-content: space-between;
}

summary::-webkit-details-marker {
display: none;
}

summary::after {
content: ‘+’;
font-size: 24px;
font-weight: 300;
color: #1a73e8;
transition: transform 0.3s ease;
}

details[open] summary::after {
content: ‘−’;
transform: rotate(0deg);
}

details p {
padding: 0 20px 18px 20px;
margin: 0;
color: #4a4a4a;
font-size: 15px;
line-height: 1.6;
}

Understanding storage consumption matters for every Linux user. Many people wonder about the best approach to determine space usage. This guide explains how to check file size in Linux using four reliable techniques.

Linux treats everything as a file. This includes documents, images, programs, and directories. Knowing storage usage helps manage your system better. You can identify large files and free up space when needed.

If you’re using a Chromebook with Linux enabled, these commands work perfectly in the Linux terminal.

Method 1: Using the du Utility

The du utility remains the most accurate way to check file size in Linux. It displays actual disk consumption for files and folders.

Basic syntax:

du -h filename

The -h flag shows results in a readable format. You see sizes in KB, MB, or GB.

Example:

du -h myfile.txt
4.0K myfile.txt

For directories, add the -s flag:

du -sh /home/user/documents
48K /home/user/documents

This approach works well for managing storage on Chromebooks that run Linux apps.

Method 2: Listing Files with ls

The ls utility provides quick size information, along with other details. It displays permissions, ownership, and timestamps as well.

Basic syntax:

ls -lh filename

Example output:

-rw-r--r-- 1 user group 987M Apr 12 13:37 document.txt

The fifth column displays the size. Adding -h converts bytes into readable units.

Important note: This method cannot directly measure directory sizes. Use du for folders instead.

Command Purpose
ls -l Show detailed file info
ls -lh Display human-readable sizes
ls -lS Sort by size (largest first)

Method 3: Finding Files by Size

The find utility locates files based on various criteria, including size. This helps discover large items across your system.

Examples:

find / -size 50M
find / -size +50M -size -100M

The first command locates files exactly 50MB. The second finds items between 50 MB and 100 MB.

Method 4: Detailed Information with stat

The stat utility reveals comprehensive metadata about files. It shows exact byte counts, permissions, and timestamps.

Basic syntax:

stat filename

For size only, use:

stat -c "%s" filename

This returns the precise byte count without extra details.

Quick Reference

Method Best Use Case Shows Directory Size
du -h Actual disk usage Yes
ls -lh Quick overview No
find -size Locating by size No
stat Exact byte count No

Key Differences Between du and ls

These utilities report different values for certain files. Sparse files contain empty sections. The ls command shows apparent size. The du utility displays actual disk consumption.

Choose du when you need precise storage measurements. Pick ls for quick overviews during terminal sessions on ChromeOS.

Summary

Learning how to check file size in Linux improves your system management skills. The du command provides the most accurate disk usage figures. The ls utility offers quick file listings with size information. The find command helps locate items by size criteria. The stat utility delivers detailed metadata, including exact byte counts.

Each method serves different purposes. Pick the right tool based on your specific needs. Regular monitoring keeps your Linux system running smoothly.

FAQs

Which command shows the most accurate file size in Linux?

The du command shows the most accurate disk usage. It reports actual space consumed on disk rather than just file size. Use du -h for human-readable output that displays sizes in KB, MB, or GB format.

Can I check multiple file sizes at once in Linux?

Yes, you can check multiple files simultaneously using the ls -lh command followed by multiple filenames or wildcards. You can also use du -h with multiple paths to see disk usage for several files or directories in one command.

How do I find the largest files on my Linux system?

Use the find command with size parameters and sort the results. The command find / -type f -size +100M displays all files larger than 100MB. Combine with sort and head to list the top largest files on your system.

What’s the difference between apparent size and actual disk usage?

Apparent size is the number of bytes in a file, shown by ls. Actual disk usage is the space consumed on disk, shown by du. Files occupy space in blocks, so actual usage is often larger than apparent size due to block allocation.

Do these file size commands work on Chromebooks with Linux?

Yes, all these commands work perfectly on Chromebooks with the Linux development environment enabled. Open the Terminal app and use du, ls, find, or stat commands just like on any other Linux system.