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
dfcommand: Thedfcommand is the most popular and easy way to check disk space usage.dfDisplays the amount of disk space available on the file system.
-
Human-readable
dfoutput: We can usedfcommand with the-hoption in order to show units in a more human friendly way by using KB,MG,GB etc.df -hShows 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 -TShows 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 -icommand.df -iDisplays 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 -hcommand. We should also provide the file system path like/dev/sda1or/dev/vda1.df -h /dev/sda1Shows 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
-hToption like below.df -hTCombines 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
tmpfsordevtmpfslike below. We should specify with the-x.df -h -x tmpfs -x devtmpfsExcludes specific file systems (e.g., tmpfs, devtmpfs) from the output.
-
ducommand 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 /homeDisplays disk usage of a directory and its subdirectories.
-
Human-readable
duoutput: We can show disk usage with theducommand in a more readable way with the-hoption.du -h /homeShows disk usage in human-readable format for a directory.
-
Summarize
duoutput: Theducommand can be used to display disk usage summary for a specific directory.du -sh /homeProvides a summary of disk usage for a directory.
-
Show disk usage of all subdirectories: By default the
ducommand displays all sub directories disk usage. We can limit the depth of the sub directories with the--max-depth. For example the--max-depth=1used to list all child directories for the specified directory or path.du -h --max-depth=1 /homeDisplays disk usage of all subdirectories within a directory.
1.2G /home/ismail 1.2G /home -
Sort
duoutput by size:du -ah /home | sort -rh | head -n 10Shows 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.lsblkLists 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
lsblkoutput:lsblk -fDisplays 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: Thencduis cli based UI which is pretty good with helpfull graphics and information.sudo apt install ncdu ncduncduis an interactive disk usage analyzer. -
Check disk space with
dffor all file systems:df -aShows all file systems including those with 0 blocks.
-
Check disk space of a directory without following symbolic links:
du -h -L /homeShows 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.