Linux Disk Management and File System Related Commands

Introduction

Here are some commands to assist with mastering disks and file systems on Linux.

See Disk Space Available

duf versus df -h

duf is a much more user friendly version of df -h which is included with most Linux distributions. As of Ubuntu 22.04 duf is included with the operating system, but otherwise you can install it on a Debian based distribution like so:

wget https://github.com/muesli/duf/releases/download/v0.8.1/duf_0.8.1_linux_amd64.deb
dpkg -i duf_0.8.1_linux_amd64.deb

Next, to see disk usage, do this:

duf -hide special

Disk Usage by Directory

We often have to see how much disk space is being used by specific directory or all the files in a specific directory. At other times and under high pressure one might have to find a particularly large file that is filling up the file system causing the operating system to crash.

Most Linux distributions aleady have du installed, but there is a  better alternative called ncdu. Both utilities take a while to calculate disk space if you have a large amount of files on the file system, as it has to traverse all the files and directories. Both utilities are really useful to find a particular large file in the system if you don’t know where it might be.

ncdu versus du

ncdu isn’t installed by default on Debian based distributions but it has a smarter interface than du. Claims are also it’s faster. The other bonus of ncdu is by default it sorts by size. In crisis mode  you would want to use this utility.

To install ncdu on a Debian based distribution:

apt install ncdu

du

The du command is quite powerful but as with ncdu be aware of performance implications if you’re running it against large subdirectories. The first time you run du it will take longer than the second time, because on the second run it should be taking advantage of caching of stat() metadata.

If you have a vague clue in which parent directory the large file in question is, first change to that specific directory, then do the following:

du -h --max-depth=1
du --summarize

du see usage sorted by size

If you don’t have access to ncdu you can use the du command pipe syntax below to sort disk usage by size in the current directory:

sudo du -ks $(ls -d */) | sort -nr | cut -f2 | xargs -d '\n' du -sh 2> /dev/null

Note: On a 800 GB server with an SSD array which 100 000s of files it took around 10 minutes before output was produced.

Determine the Linux file system type

df -Th | grep "^/dev"

Find out which Linux partitions exist on a file system

fdisk -l

From the manual:

> List  the  partition  tables  for  the specified devices and then exit.  If no devices are given, those mentioned in /proc/partitions (if that exists) are used.

References

Share this article

Leave a Reply

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

Scroll to Top