• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
NameHero® Blog

NameHero® Blog

Web Hosting Tips & Resources From NameHero

  • AI Agents
    • OpenClaw
    • Claude Code
    • n8n
    • Hermes Agent
    • Open WebUI
    • Docker
  • Hosting
    • Web Hosting
    • WordPress Hosting
    • WooCommerce Hosting
    • Enterprise Hosting
    • Email Hosting
    • HeroicGuard
    • GPU Hosting
    • Website Builder
  • VPS
    • Managed VPS
    • Unmanaged VPS
    • Flex VPS
  • Reseller
  • Gaming
  • Domains
  • Account
  • Blog Home
  • Categories
  • Authors

How To Check File And Folder Disk Space In Linux

Bhagwad Park

Published on: July 23, 2018

Categories: VPS Hosting 0

The Linux command line can leave you feeling as if you don’t have all the information at your fingertips. In a traditional GUI, you can just peek at the bottom of the window and see how much space a folder is using. Or you can hover over a file or folder and get its size. You even have graphical indications of how much space you have left on your hard disk.

However just because this information is not instantly visible on a command line interface like CentOS, doesn’t mean it’s not easily available. With the right commands, you can get a lot more information out of the command line, and that includes knowing how much free space you have. In this tutorial, I’ll show you how to check free space, and get the storage consumption of files and folders in MB.

But First: Space Permissions with Sudo

Many files and folders are restricted to admins only. Additionally, commands like fdisk require sudo permissions to run. In these examples, I’m not logged into root, so I’ll sometimes be using sudo. Here’s a tutorial on how to give users sudo permissions.

Checking Free Space

To get the free space available on all your disks, type the following command:

sudo fdisk -l

The volumes on CentOS are labeled like this:

/dev/vda
/dev/vdb
etc...

In addition, you’ll sometimes see a number after these disks – these indicate partitions. In the screenshot below, I don’t have any partitions yet:

Get Free Disk Space with fdisk

I have two volumes, but only the first one is of any significant size – 26.8 GB.

So that’s how you check free space on Linux. Now let’s see how we get the sizes of files an folders.

Getting Folder Space Allocation

We use the “du” command in any given directory for a breakdown of the sizes of the individual folders. For example, here I’m in the “usr” directory when I use the following command:

du | more

The “more” command is so that everything doesn’t just scroll up too fast for me to see. Instead, it’ll present me with information a little bit at a time.

File sizes for individual folders

Here you can see that in my current “usr” directory, I have large folders like “bin”, “sbin” etc. I haven’t sorted these in any particular order yet. Note that the size is displayed in bytes. If we want, we can change this to a more convenient human readable format by adding the -h parameter:

du -h

This gives us the following:

File size in MB

Much better! It’s much more intuitive to get the sizes in MB. However, if we want to find out which folders are taking up the most space, we need to sort this list in descending order. We do this by piping the output of du to the “sort” command with the “-hr” parameters like this:

du -h | sort -hr | more

Which gives us:

Sort Descending by Folder

This shows us that there were much bigger folders further down, which are now revealed due to the descending sort. Useful right?

Now that we have the sizes of folders, let’s get the file sizes as well.

Checking the File Sizes

To get the files as well as the folders in our net, we just need to use the “-a” parameter with du. So the above command becomes:

du -ah | sort -rh | more

And now all the files sizes are visible in descending order:

Get the File and Folder Disk Space

You can even pass a specific folder to “du” and get the sizes of files and folders inside it. You don’t have to be physically present inside it. So we could have gotten the results of /usr by typing:

du /usr

from anywhere else. These commands should allow you to get an idea of what’s going on with your system, which files are using the maximum space, and which folders are the biggest!

Bhagwad Park Profile Picture
Bhagwad Park

I’m a NameHero team member, and an expert on WordPress and web hosting. I’ve been in this industry since 2008. I’ve also developed apps on Android and have written extensive tutorials on managing Linux servers. You can contact me on my website WP-Tweaks.com!

Related Posts

Git Bisect: A Step-by-Step Tutorial

Git bisect is a useful tool that git provides, allowing you to narrow down the commit that introduced a bug in your project.

How to Use Vim Search and Replace in Linux

The vim search and replace functionality in Linux consists of a series of very powerful tools - but also simple ones to get started easily.

How to Tar and Gzip a Folder

Here's how to archive and compress a folder so that it's easy to move it from one location to another - In both Linux AND Windows!

Curl vs Wget: Choosing the Right Tool for the Job

Linux has two popular tools for getting data from third party websites. Here's the difference between curl and wget.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Follow & Subscribe

Exclusive promos, content and more!


Most Popular Posts

NameHero’s Recommended WordPress Plugin and Theme Setup

WordPress Hosting vs. Web Hosting – What’s The Difference?

How To Increase The InnoDB Buffer Pool Size

How To Fix A Stuck All-in-One WP Migration Import

How To Add A Subdomain In Cloudflare

Top Categories

  • WordPress
  • WordPress Tutorials
  • OpenClaw Hosting
  • Enterprise Hosting
  • WooCommerce
  • Web Hosting
  • Resellers
  • Website Security
  • Website Development
  • Website Performance
  • VPS Hosting
  • SEO Tips
  • Announcements
  • Domain Registration
NameHero

NameHero® proudly provides web hosting to over 40,000 customers with 99.9% uptime to over 750,000 websites.

  • Master Card
  • Visa
  • American Express
  • Discover
  • Paypal
Products
  • Web Hosting
  • Managed VPS Hosting
  • Unmanaged VPS Hosting
  • Flex VPS Hosting
  • WordPress Hosting
  • WooCommerce Hosting
  • Reseller Hosting
  • Enterprise Hosting
  • GPU Hosting
  • Email Hosting
  • HeroicGuard
  • Domains
  • Website Builder
  • AI Agent Hosting
Help & Support
  • NameHero Blog
  • NameHero Gaming Blog
  • Support
  • Help Center
  • Migrations
  • Affiliates
  • Gaming Affiliates
  • Call 1-855-984-6263
Company
  • About Us
  • Contact Sales
  • Reviews
  • Uptime
  • We're Hiring

Copyright © 2026 Name Hero, LLC. All rights reserved.
NameHero® is a registered trademark.

  • Privacy Policy
  • Terms of Use
  • Acceptable Use Policy
  • Payment Policy
  • DMCA