Checking file and folder sizes in Linux makes it easier to find what is filling a filesystem before logs, backups, package caches, or application data push a mount point to 100 percent usage.

The main tool for this job is du, which walks a path and reports the disk space used by each file or directory. -s collapses the result to a single summary, -a includes individual files, and --max-depth keeps directory scans at a readable level when only the top of the tree matters.

du reports allocated filesystem space by default, not always the logical length shown by ls -l or stat. That difference matters for sparse files, compressed or copy-on-write filesystems, and directories that cross into other mounts. Large or protected trees can also return permission errors, so add sudo when needed and use -x when a scan should stay on one filesystem.

Steps to check file and folder sizes with du in Linux:

  1. Summarize a directory when only the total used space matters.
    $ du -sh /srv/size-demo
    2.3M	/srv/size-demo

    -s shows one total for the path, and -h formats that total with units such as K, M, or G.

  2. Show the immediate child directories before drilling deeper into one subtree.
    $ du -h --max-depth=1 /srv/size-demo | sort -h
    16K	/srv/size-demo/archive
    260K	/srv/size-demo/logs
    2.3M	/srv/size-demo

    --max-depth=1 keeps the report at the target directory and its direct children, and sort -h understands the human-readable suffixes produced by du -h.

  3. Include individual files as well as folders when the large item is not yet obvious.
    $ du -ah /srv/size-demo | sort -h | tail -n 8
    0	/srv/size-demo/sparse.img
    4.0K	/srv/size-demo/tiny.txt
    12K	/srv/size-demo/archive/report.bin
    16K	/srv/size-demo/archive
    256K	/srv/size-demo/logs/app.log
    260K	/srv/size-demo/logs
    2.0M	/srv/size-demo/backup.img
    2.3M	/srv/size-demo

    -a adds regular files to the report instead of listing directories only.

  4. Check the used space of one specific file when the exact on-disk footprint matters.
    $ du -h /srv/size-demo/backup.img
    2.0M	/srv/size-demo/backup.img

    Without -h, du prints the value in 1024-byte blocks by default, which is useful when a script expects raw block counts.

  5. Compare allocated space with apparent size when a sparse file seems much smaller than expected.
    $ du -h /srv/size-demo/sparse.img
    0	/srv/size-demo/sparse.img
    $ du -h --apparent-size /srv/size-demo/sparse.img
    4.0G	/srv/size-demo/sparse.img

    The first command shows blocks actually allocated on disk. --apparent-size instead shows the logical file length, which is why sparse files can appear huge in ls -l but tiny in du.

  6. Keep a scan on one filesystem when checking a system path that may contain other mounts below it.
    $ du -xh --max-depth=1 /var | sort -h
    4.0K	/var/backups
    4.0K	/var/local
    4.0K	/var/mail
    4.0K	/var/opt
    4.0K	/var/spool
    4.0K	/var/tmp
    280K	/var/log
    504K	/var/cache
    4.0M	/var/lib
    4.8M	/var

    -x skips directories that live on a different filesystem from the starting path. Add sudo if a regular user cannot read every entry below /var.

  7. Add a grand total when several specific paths need to be compared as one group.
    $ du -sch /srv/size-demo/archive /srv/size-demo/logs /srv/size-demo/backup.img
    16K	/srv/size-demo/archive
    260K	/srv/size-demo/logs
    2.0M	/srv/size-demo/backup.img
    2.3M	total

    -c prints a final total line after all supplied paths, which is useful when combining a few directories and files into one space check.