Disk space usage

Posted by Lukas Hajdu on Tue, Oct 8, 2019

A filespace can be estimated with the disk utility program - du.

The disk utility is recursive for directories by default. To show the amount of space used only for the first level use the option --max-depth=1. The option --max-depth=0 is the same as --summarize and it will display only a total space used.

Show disk usage:

 1lukash@ubuntu:/$ sudo du --max-depth=1 / | sort -k 2
 2du: cannot access '/proc/22736/task/22736/fd/4': No such file or directory
 3du: cannot access '/proc/22736/task/22736/fdinfo/4': No such file or directory
 4du: cannot access '/proc/22736/fd/3': No such file or directory
 5du: cannot access '/proc/22736/fdinfo/3': No such file or directory
 65780099	/       # total space used
 715244	/bin
 8144372	/boot
 94	/cdrom
100	/dev        # pseudo-file
117064	/etc
12432	/home
13847160	/lib
144	/lib64
1516	/lost+found
164	/media
174	/mnt
1816	/opt
190	/proc       # pseudo-file
2016	/root
211008	/run
2215596	/sbin
23519611	/snap
244	/srv
250	/sys        # pseudo-file
2640	/tmp
271866408	/usr
28763600	/var

The du command displays space usage on all file systems. To skip directories on different file systems than the root partition use the option -x. This will ignore directories like /dev, /proc, /run, and /sys. To display sizes in human-readable formats use the option -h.

 1lukash@ubuntu:/$ sudo du --max-depth=1 -xh / | sort -k 2
 25.1G	/
 315M	/bin
 4141M	/boot
 54.0K	/cdrom
 66.9M	/etc
 7432K	/home
 8828M	/lib
 94.0K	/lib64
1016K	/lost+found
114.0K	/media
124.0K	/mnt
1316K	/opt
1416K	/root
1516M	/sbin
1616K	/snap
174.0K	/srv
1840K	/tmp
191.8G	/usr
20746M	/var
21
22lukash@ubuntu:/$ sudo du --summarize -xh
235.1G	.

The whole command can be examined on the explainshell.com.



comments powered by Disqus