Working with servers, you might need to check the information of disk usage of files and directories on your machine. “du” (Disk Usage) command serves this purpose in Linux/Unix. The “du” command displays the files and directory sizes in a recursively manner and accepts different parameter options that can be used to display results in various formats.
– Get disk usage summary of a directory tree and each of its subDi directories:
du <directory path>
– Use “-h” option with “du” to get disk usage summary sizes in “Human readable format” (Bytes, Kilobytes, Megabytes, Gigabytes etc.)
du -h <directory path>
– Get the summary of a grand total disk usage size of an directory using the option “-s”
du -sh <directory path>
– Get disk usage of all the files and directories using “-a” option
du -a <directory path>
– Combining “-a” and “-h” options displays disk usage of all files and directories in human readeable format
du -ah <directory path>
– “-c” flag along “-h” provides a grand total usage disk space at the last line.
du -ch <directory path>
– Excluding some files matching some pattern can be achieved using “–exclude” option.
du -ah --exclude="*.txt" <directory path>
– “–time” option can be used to display modification time for files & directories
du -ha --time <directory path>
– Similary, flags “-k” and “-m” can be used to display size in Kilobyte and Megabytes respectively.
du -k <directory path> du -m <directory path>