Linux: Check the Size of a Directory with ls Command in 2025

In today’s fast-moving tech world, Linux is still a favorite for developers, system admins, and tech lovers. One basic but important task in Linux is checking the size of a directory in Linux. As we move into 2025, it’s more important than ever to manage your disk space wisely. With tons of data being created every day, knowing the directory size in Linux helps you keep your system clean and running fast.

This guide by Owrbit will show you how to check the size of a directory in Linux using the simple and commonly used ls command. Even though the ls command is mostly used to list files and folders, it can also give you helpful information about the directory size in Linux. This makes it easier to find out which folders are taking up the most space.

Whether you’re new to Linux or have been using it for years, learning how to check the size of a directory in Linux can help you clean up your system, remove unwanted files, and plan for more storage in the future. It’s a quick and easy way to understand your files better and keep everything organized.

By the end of this guide, you’ll know exactly how to use the ls command to find the directory size in Linux. We’ll keep things simple, so even beginners can follow along. No matter what you use Linux for, knowing the size of a directory in Linux is a useful skill that can save time and keep your system running smoothly.

Let’s get started and learn how to check the directory size in Linux like a pro!

Introduction to Linux :

Linux is a powerful, open-source operating system used by millions of people around the world. It’s the backbone of most servers, cloud systems, Android devices, and even some personal computers. Unlike Windows or macOS, Linux is free to use, and anyone can download, modify, and share it.

Linux

At its core, Linux is known for being fast, secure, and stable. That’s why developers, system administrators, and tech enthusiasts prefer it for everything from writing code to running websites. It offers great flexibility, so you can customize it exactly the way you want.

Linux comes in different versions called distributions (or distros) like Ubuntu, Fedora, Debian, and CentOS. Each one has its own style and tools, but they all work on the same Linux core.

One thing that makes Linux different is its use of the command line. While many distros come with a graphical interface (like Windows), a lot of Linux tasks are done using typed commands. This gives users more control and speed, especially when managing files, installing software, or setting up servers.

Whether you’re just curious about Linux or planning to use it for work or personal projects, learning the basics can open up a whole new world of technology.

What is ls Command in Linux :

The ls command in Linux is one of the most commonly used commands. It stands for “list”, and it is used to show the contents of a directory. When you type ls in the terminal and press Enter, it lists all the files and folders inside your current directory.

What is ls Command in Linux

Basic Usage:

ls

This simple command shows all the files and directories in your current location.

Common Options with ls:

Here are a few popular options that make ls more useful:

  • ls -l: Lists files and folders in a long format, showing details like permissions, owner, file size, and modification date.
  • ls -a: Shows all files, including hidden ones (those starting with a dot .).
  • ls -lh: Combines long format with human-readable sizes (like KB, MB instead of just bytes).
  • ls -la: Lists all files, including hidden ones, in long format.

Example:

ls -lh

This command lists all files with sizes in KB/MB/GB and other details in a readable format.

How to Use ls Command to Check Size of a Directory in Linux :

Many Linux users think of the ls command only as a tool to list files and folders, but it can also show some basic size information. However, it’s important to understand that the ls command does not directly show the total size of a directory in Linux — it only shows the sizes of individual files, not the total directory size in Linux.

Still, you can use ls in a helpful way to see the sizes of the files inside a folder.

Checkout Debian vs Arch Linux: Choosing the Perfect Linux Distribution

Use ls Command to Check Size of a Directory in Linux

  • Step 1: Open Terminal
    • Open your Linux terminal.
  • Step 2: Use ls -lh to See File Sizes in Human-Readable Format
    • -l shows the list in long format (with details).
    • -h makes file sizes easy to read (like 1K, 200M, 2.1G).
    • This command helps you view the size of each file in the directory, but not the full size of the directory.
ls -lh
  • Example Output:
-rw-r--r--  1 user user 2.3K Apr 30 10:22 file1.txt  
-rw-r--r--  1 user user 1.1M Apr 30 10:25 video.mp4

So, while ls -lh gives an idea of which files are large, it doesn’t calculate the total directory size in Linux.

Better Way to Check the Size of a Directory in Linux :

To check the actual size of a directory in Linux, the better tool is the du (disk usage) command.

Better Way to Check the Size of a Directory in Linux

Use This Command:

du -sh foldername
  • -s: summarize the total size
  • -h: human-readable format

Example:

du -sh /home/user/Documents

This will show the total size of a directory in Linux, including all files and subfolders inside.

Using du Command vs. ls Command in Linux to Check Size of a Directory :

When working with Linux, two commonly used commands for checking file and directory sizes are the du (disk usage) and ls commands. While both are helpful, they serve different purposes and give different kinds of information. Here’s a quick comparison to help you understand when to use each one:

Featurels Commanddu Command
PurposeLists files and directoriesShows total disk usage of a directory
Size ReportingShows individual file sizesShows total directory size (including subdirectories)
Hidden FilesCan show hidden files with the -a optionShows hidden files as part of the total size
Command Formatls -lh /path/to/directorydu -sh /path/to/directory
DisplaysOnly files and folders in the current directoryTotal size of the specified directory and its contents
Best Used ForViewing the contents of a directoryChecking overall disk usage of a directory
Details ProvidedFile permissions, owner, size, and modification timeTotal disk space used by a directory, including nested subdirectories
SuitabilityQuick look at files and file sizesUnderstanding overall space usage of directories and subdirectories
File and Folder SummaryDoesn’t provide a total directory sizeProvides a summarized size of the directory

While both commands are useful, the du command is your go-to tool for checking the size of a directory in Linux. The ls command is best for listing files and their sizes, but it doesn’t give a total size of the directory itself.

By using both commands together, you can get a complete picture of your Linux system’s file structure and disk usage.

Conclusion: Maximizing Your Linux Experience

Understanding how to check the size of a directory in Linux is an essential skill for anyone using this powerful operating system. Whether you’re managing a few files or handling large directories, knowing the directory size in Linux can help you keep your system organized and running efficiently.

Using the ls command is great for quickly viewing individual file sizes, but if you want the total size of a directory in Linux, you’ll need to use the du command. This command gives you a complete picture of the directory size in Linux, including all files and subdirectories.

By regularly checking the size of a directory in Linux, you can avoid running out of disk space, manage your files better, and make sure your system runs smoothly. Whether you’re a beginner or an experienced Linux user, understanding how to check the directory size in Linux is a simple yet powerful way to keep control of your storage.

Maximizing your Linux experience is about more than just knowing the commands — it’s about using them wisely. With the right tools, like the ls and du commands, you’ll be able to manage the size of a directory in Linux and optimize your storage for the best performance.

Take the time to explore these commands, and you’ll soon have a much clearer understanding of the directory size in Linux and how to manage your file system like a pro!

Checkout Debian vs Arch Linux: Choosing the Perfect Linux Distribution


Discover more from Owrbit

Subscribe to get the latest posts sent to your email.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply