Running low on disk space wondering how much disk space you have left on your Linux system? Whether you’re a Linux beginner or a seasoned pro, it’s important to understand how to manage your system’s storage effectively. Linux provides several simple commands to give you an overview of disk usage.
we’ll show you easy ways to check how much space is being used, how much is free, and how to identify large files or directories that might be eating up your storage. With these tools at your disposal, you can easily monitor your system and avoid running into space-related issues.
Below are the most commonly used methods:
1. Using df
(Disk Free)
The df
command shows the disk space usage of all mounted filesystems.
admin@atbytes:~$ df -h
-h
: Displays sizes in human-readable format (e.g., KB, MB, GB).- Output includes:
- Filesystem: The partition or disk.
- Size: Total disk space.
- Used: Space used.
- Available: Free space.
- Use%: Percentage of space used.
- Mounted on: The mount point.
To check a specific filesystem or directory:
admin@atbytes:~$ df -h /path/to/directory
This will show something like:
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 50G 20G 30G 40% /
/dev/sdb1 200G 150G 50G 75% /home
- Size: The total size of the disk.
- Used: How much space is currently used.
- Avail: How much space is still available.
- Use%: The percentage of space used.
- Mounted on: Where the disk is mounted (usually
/
for the root filesystem, and/home
for your personal files).
2. Using du
(Disk Usage)
The du
command shows the disk usage of files and directories.
admin@atbytes:~$ du -sh /path/to/directory
-s
: Summarizes the total usage of the directory.-h
: Displays sizes in human-readable format.
Example:-
admin@atbytes:~$ du -sh ~/Documents
You’ll see something like this:
2.3G /home/username/Documents
This means your Documents
folder is using 2.3GB of space.
To check disk usage for all files and subdirectories within a directory:
admin@atbytes:~$du -h /path/to/directory
3. Using lsblk
(List Block Devices)
The lsblk
command lists information about block devices (disks and partitions), including their size and mount points.
admin@atbytes:~$ lsblk
- Output includes:
- NAME: Device name.
- SIZE: Total size of the device.
- MOUNTPOINT: Where the device is mounted.
Example:
admin@atbytes:~$ lsblk
Output:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 50G 0 disk ├─sda1 8:1 0 40G 0 part / └─sda2 8:2 0 10G 0 part /home sdb 8:16 0 100G 0 disk └─sdb1 8:17 0 100G 0 part /mnt/data
- Explanation:
sda
is a 50GB disk with two partitions:sda1
(40GB) is mounted as/
.sda2
(10GB) is mounted as/home
.
sdb
is a 100GB disk with one partition (sdb1
) mounted at/mnt/data
.
4. Using fdisk
(Partition Table Manipulator)
The fdisk
command can display disk partition information.
admin@atbytes:~$ sudo fdisk -l
-l
: Lists partition tables for all disks.- Requires
sudo
privileges.
5. Using ncdu
(NCurses Disk Usage)
ncdu
is an interactive tool for analyzing disk usage.
- Install
ncdu
(if not already installed):
- On Debian/Ubuntu:
bash sudo apt install ncdu
- On Red Hat/CentOS:
bash sudo yum install ncdu
- Run
ncdu
:
admin@atbytes:~$ ncdu /path/to/directory
- Navigate through directories using arrow keys.
- Press
q
to quit.
Example:
Analyze disk usage in the /var
directory:
admin@atbytes:~$ ncdu /var
Output (Interactive):
--- /var --------------------------------------------------------- 500.0 MiB [##########] /lib 100.0 MiB [##] /cache 20.0 MiB [ ] /log 620.0 MiB [##########] total
- Explanation:
- Use arrow keys to navigate.
- Press
Enter
to drill down into directories. - Press
q
to quit.
6. Using baobab
(Graphical Disk Usage Analyzer)
If you prefer a graphical interface, you can use baobab
(Disk Usage Analyzer).
- Install
baobab
:
- On Debian/Ubuntu:
bash sudo apt install baobab
- On Red Hat/CentOS:
bash sudo yum install baobab
- Launch
baobab
:
admin@atbytes:~$ baobab
Select a directory (e.g., /home
) to analyze.
Output (Graphical):
- A pie chart or treemap showing disk usage for the selected directory.
7. Using inxi
(System Information Tool)
inxi
is a versatile tool that provides detailed system information, including disk usage.
- Install
inxi
:
- On Debian/Ubuntu:
bash sudo apt install inxi
- On Red Hat/CentOS:
bash sudo yum install inxi
- Run
inxi
to check disk space:
admin@atbytes:~$ inxi -D
Example:
admin@atbytes:~$ inxi -D
Output:
Drives: HDD Total Size: 150.0GB ID-1: /dev/sda size: 50.0GB ID-2: /dev/sdb size: 100.0GB Partition: ID-1: / size: 40.0GB used: 20.0GB (50%) fs: ext4 dev: /dev/sda1 ID-2: /home size: 10.0GB used: 5.0GB (50%) fs: ext4 dev: /dev/sda2 ID-3: /mnt/data size: 100.0GB used: 60.0GB (60%) fs: ext4 dev: /dev/sdb1
- Explanation:
- Total disk size: 150GB.
/dev/sda1
(40GB) is 50% used./dev/sdb1
(100GB) is 60% used.
8. Using stat
(File System Statistics)
The stat
command can display information about a specific file or filesystem.
admin@atbytes:~$ stat -f /path/to/directory
-f
: Displays filesystem information.- Output includes:
- Total size.
- Free space.
- Used space.
Example:
Check filesystem information for /home
:
admin@atbytes:~$ stat -f /home
Output:
File: "/home" ID: 1234567890abcd Namelen: 255 Type: ext4 Block size: 4096 Fundamental block size: 4096 Blocks: Total: 2621440 Free: 1048576 Available: 1048576 Inodes: Total: 655360 Free: 524288
- Explanation:
- Block size: 4096 bytes.
- Total blocks: 2,621,440 (10.5GB).
- Free blocks: 1,048,576 (4.2GB).
Summary
- Quick overview: Use
df -h
. - Detailed directory usage: Use
du -sh
. - Interactive analysis: Use
ncdu
. - Graphical tool: Use
baobab
.
Choose the method that best suits your needs.