How To Check Disk Space In Ubuntu?
Thursday, Aug 8, 2024 | 4 minutes read | Update at Thursday, Aug 8, 2024
Disk space usage should be monitored or checked periodically to prevent system failures and problems. Ubuntu provides different command in order to check disk space. These commands can be used used, free, cached disk usage in different units like MB, GB etc.
-
Basic
df
command: Thedf
command is the most popular and easy way to check disk space usage.df
Displays the amount of disk space available on the file system.
-
Human-readable
df
output: We can usedf
command with the-h
option in order to show units in a more human friendly way by using KB,MG,GB etc.df -h
Shows disk space in human-readable format (e.g., KB, MB, GB).
-
Display file system type with
df
: We can show the file system type with thedf -T
.df -T
Shows disk space along with the type of file system.
-
Inodes information using
df
: Inodes are file system level information about data storage. We can display the inode usage with thedf -i
command.df -i
Displays the number of inodes used and available on each file system.
-
Check specific file system disk space: A typical Linux system use multiple file systems for different purposes. We can check specific file system disk space with the
df -h
command. We should also provide the file system path like/dev/sda1
or/dev/vda1
.df -h /dev/sda1
Shows disk space usage for a specific file system.
-
Human-readable and file system type: We can show disk usage with the file system type in a human readable way with the
-hT
option like below.df -hT
Combines human-readable format with file system type.
-
Check disk space excluding certain file systems: You can display the disk usage by excluding some file systems. For example we can exclude the temporary file systems like
tmpfs
ordevtmpfs
like below. We should specify with the-x
.df -h -x tmpfs -x devtmpfs
Excludes specific file systems (e.g., tmpfs, devtmpfs) from the output.
-
du
command to check directory space: We can list disk usage or the specific directory or path. In the following example we list disk usage for the users home directories those are located under the/home/
.du /home
Displays disk usage of a directory and its subdirectories.
-
Human-readable
du
output: We can show disk usage with thedu
command in a more readable way with the-h
option.du -h /home
Shows disk usage in human-readable format for a directory.
-
Summarize
du
output: Thedu
command can be used to display disk usage summary for a specific directory.du -sh /home
Provides a summary of disk usage for a directory.
-
Show disk usage of all subdirectories: By default the
du
command displays all sub directories disk usage. We can limit the depth of the sub directories with the--max-depth
. For example the--max-depth=1
used to list all child directories for the specified directory or path.du -h --max-depth=1 /home
Displays disk usage of all subdirectories within a directory.
1.2G /home/ismail 1.2G /home
-
Sort
du
output by size:du -ah /home | sort -rh | head -n 10
Shows the top 10 largest files and directories sorted by size.
1.2G /home/ismail 320M /home/ismail/ecommerce 303M /home/ismail/ecommerce/.git/objects 303M /home/ismail/ecommerce/.git 289M /home/ismail/ecommerce/.git/objects/pack/pack-dd745ff07c20fd46.pack 289M /home/ismail/ecommerce/.git/objects/pack 267M /home/ismail/.config 212M /home/ismail/.vscode/extensions 212M /home/ismail/.vscode 176M /home/ismail/.cache
-
Check disk space with
lsblk
: Another useful command in order to display disk usage islsblk
. Thi scommand lists partitions size.lsblk
Lists information about all available block devices.
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS loop0 7:0 0 4K 1 loop /snap/bare/5 loop1 7:1 0 161.6M 1 loop /snap/chromium/2828 loop2 7:2 0 74.2M 1 loop /snap/core22/1380 loop3 7:3 0 66.1M 1 loop /snap/cups/1044 loop4 7:4 0 505.1M 1 loop /snap/gnome-42-2204/176 loop5 7:5 0 91.7M 1 loop /snap/gtk-common-themes/1535 loop6 7:6 0 38.7M 1 loop /snap/snapd/21465 sda 8:0 0 100G 0 disk ├─sda1 8:1 0 1M 0 part └─sda2 8:2 0 100G 0 part /
-
Detailed
lsblk
output:lsblk -f
Displays detailed information including file system type.
-
Check disk usage of current directory: We can simply check the current directory size with the
du -sh .
command.du -sh .
Provides a summary of disk usage for the current directory.
-
Check disk usage with
ncdu
: Thencdu
is cli based UI which is pretty good with helpfull graphics and information.sudo apt install ncdu ncdu
ncdu
is an interactive disk usage analyzer. -
Check disk space with
df
for all file systems:df -a
Shows all file systems including those with 0 blocks.
-
Check disk space of a directory without following symbolic links:
du -h -L /home
Shows disk usage for a directory without following symbolic links.
These examples illustrate various ways to check and analyze disk space usage on an Ubuntu system, offering both basic and detailed insights into storage.