Programs and services can behave unexpectedly or stop working entirely when storage space runs tight, so it's important to know how much space is available on our system. This recipe introduces a handful of commands used to determine how large your files and directories are and how much storage is used and is available.
This recipe requires a working CentOS system. Administrative privileges may be needed depending on the permissions of the directories and files you want to inspect.
To display the storage capacity of a mounted filesystem, use the
df
command:df -h /
To view the size of a file, use the
ls
command:ls -sh file.txt
To determine the size of a directory (the sum of sizes of all of its files), use the
du
command:du -sh ~