Checking Disk Space in Linux Using Command-Line

There are numerous ways of checking Linux system disk space. A third-party app that shows the available disk space or by command-line way via the Linux Terminal two of which are df and du, where du is disk space used and df is disk space free.

1. Using du Command

Using du command for checking disk space. du stands for “Disk Usage”, using this command we can check directories disk usage.

Syntax:

$ du [OPTION HERE]... [FILE HERE]...

For help, we can use

$ du --help

du-command



For checking disk usage on a particular directory and display there size in a human-readable format.

$ du -h [PATH TO DIR]

checking disk usage using du command in human-readable format

For checking disk usage, and sort by first 3 directories that are using most maximum disk space.

$ du -a [PATH TO DIR].. | sort -n -r | head -n [NUMBER TO FILES/DIR]

sort by first 3 directories in du command

2. Using df Command

Using df command for checking disk usage. df is an abbreviation for “disk free”, it displays the amount of available disk space for file systems.

Syntax:

$ df [OPTIONS]... FILESYSTEM...

Showing disk space usage for the file system

$ df 

using df command



To show all the information for the disk space usage on all the file system “-a” is used.

$ df -a

show all the information for the disk space using df command

To show disk space usage of the file system for human “-h” is used.

$ df -h 

To show disk space usage using df command

To fetch the data just for the single directory.

$ df -hT [DIR ]..

fetch the data using df command

To see disk space usage and display specific columns.

$ df -H --output=size, used, avail

To see disk space usage and display specific columns using df command

Display the disk space usage for the file system in bytes we will use “-k” and to display it in megabytes we will use “-m”.

$ df -k

For Bytes

For bytes df command

$ df -m

For megabytes

For megabytes df command

My Personal Notes arrow_drop_up

A Computer Science and Engineering undergraduate student at IERT, Allahabad with an interest in Programming, Data Science/AI and web development

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.