Filesystem Space Information
With suitable options, the find and ls commands report file sizes, so with the help of a short awk program, you can report how many bytes your files occupy:
$ find -ls | awk '{Sum += $7} END {printf("Total: %.0f bytes\n", Sum)}'
Total: 23079017 bytes
However, that report underestimates the space used, because files are allocated in fixed-size blocks, and it tells us nothing about the used and available space in the entire filesystem. Two other useful tools provide better solutions: df and du.
The df Command
df (disk free) gives a one-line summary of used and
available space on each mounted filesystem. The units are
system-dependent blocks on some systems, and kilobytes on others. Most
modern implementations support the -k
option to force
kilobyte units, and the -l
(lowercase L) option to
include only local filesystems, excluding network-mounted ones. Here
is a typical example from one of our web servers:
$ df -k
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda5 5036284 2135488 2644964 45% /
/dev/sda2 38890 8088 28794 22% /boot
/dev/sda3 10080520 6457072 3111380 68% /export
none 513964 0 513964 0% /dev/shm
/dev/sda8 101089 4421 91449 5% /tmp
/dev/sda9 13432904 269600 12480948 3% /var
/dev/sda6 4032092 1683824 2143444 44% /ww
GNU df provides the
-h
(human-readable) option to produce a more compact,
but possibly more confusing, report:
$ df -h
Filesystem Size Used Avail Use% Mounted on /dev/sda5 4.9G 2.1G 2.6G 45% / /dev/sda2 38M 7.9M 29M 22% ...
Get Classic Shell Scripting now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.