Skip to main content

Command Palette

Search for a command to run...

Disk usage and management

Guide to Disk Commands: df, du, free, mount, umount

Published
2 min read
Disk usage and management
S

Growing in DevOps, together! 🤝 | Associate Software Engineer at Tech Mahindra | Enthusiastic about automation, cloud solutions, and efficient software delivery. | Let's connect, collaborate, and learn from each other!

1. df (Disk Filesystem Usage)

The df command displays the amount of disk space used and available on mounted filesystems.

Common Options:

-h → Human-readable format

-T → Shows file system type (e.g., ext4, xfs)

-i → Displays inode usage instead of disk space

  1. To show the disk usage in human-readable format (MB/GB).

     df -h
    

  2. To force the output to show sizes in KB/GB/MB.

    BM (mega bytes), BG(giga), BK (Kilobytes)

     df -h -BK
    
  3. To display file system

df -T


2. du (Disk Usage)

It shows the size of files and directories.

Common Options:

-s → Shows total size of a directory

-h → Human-readable format

-cDisplays a total at the end of the output.

-a → Shows the size of all files (not just directories).

  1. To displays total size of /home/user/ in a human-readable format.

     du -sh <directory-name>
    

  2. For more granular info - files

     du -ah <filename>
    

  3. To display a grand total

     du -ahc
    


3. free

It is used to check system memory usage in Linux, including RAM and swap space.

  1. Displays memory usage in bytes by default.

     free -h
    

  2. To continuously monitor memory usage at regular intervals.

     free -s N
    

    The -s <seconds> option allows you to set the refresh rate.

    Keep refreshing memory after N sec

  3. Exit after repeating N times


    4. mount (Mount a Filesystem)

    The mount command attaches a storage device (e.g., USB, external drive) to a directory in the filesystem.

    1. To mount /dev/sdb1 (USB) to /mnt/usb.

       mount /dev/sdb1 /mnt/usb
      

      Common Options:

      mount -o ro /dev/sdb1 /mnt/usb → Mount in read-only mode

      mount -t ext4 /dev/sdb1 /mnt/usb → Mount with a specific filesystem type

  1. To list all mounted filesystems:

     mount | column -t
    


5. unmount (Unmount a Filesystem)

The umount command detaches a mounted filesystem.

  1. To unmount the USB drive from /mnt/usb.

     umount /mnt/usb