du stands for disk usage. This simple linux command provides a summary of harddisk or storage space disk usage. It has many parameter arguments that can provide results in many screen format. du command can also summarize files and directories in a recursive manner.
Here are several usage of to use the du (disk usage) command.
# cd /home/vertitoTo list the files and directories from there
# ls -laShow summary in bytes
-rw-r--r-- 1 root root 29 2007-08-11 11:57 file.txt
drwxr-xr-x 2 root root 4096 2007-08-11 11:57 folder1
# du -bNow, let us get a more human readable results
4096 ./folder1
8221 .
# du -a
4 ./file.txt
4 ./folder1
12 .
# du -ahThe above shows that my file.txt has about 4K of filesize rounded to nearest power of 1024K including . an ..
4.0K ./file.txt
4.0K ./folder1
12K .
Now, let us it in bytesThe above is the same results you get from issuing ls -la command. 8221 is . and ..
# du -ab
29 ./file.txt
4096 ./folder1
8221 .
Now let us do it once again in human readable form
# du -abhYou can also exclude file glob pattern or shell expression for files like so
29 ./file.txt
4.0K ./folder1
8.1K .
# du -abh --exclude='file.txt'Recursive directory disk usage summary can also be achieved by doing the default usage without any parameters
# du -abh --exclude='*.txt'
4.0K ./folder1
8.0K .
# cd /homeYou can also limit the recursive search dept like so
# du
# du --max-depth=2which search on the 2nd level of directory only and ignores any folder found above the 2nd level folders.
Getting the summarized return in a human readable form
# du -shAlternatively if you wish to get the last time modification
# du -ah --time
4.0K 2007-08-11 11:57 ./file.txt
4.0K 2007-08-11 11:57 ./folder1
12K 2007-08-11 11:57 .
If you are using mbox type of mail storage handling, these commands can be handy checking and reporting partition and/or folder disk usage when incorporated inside a shell scripts. Furthermore, you can create and generate your TOP 10 users with largest mails on monthly or weekly basis that could give you more detailed email report and alerts from it..
At regular interval and again using a script, you can also watch and monitor folder/partition usage changes and alerts you for certain specified thresholds like for /home or /var/ftp or /tmp.