10 useful du (disk usage) commands to determine disk usage of files and directories

s2 0

The Linux “from“(Disk usage) is a standard Unix / Linux Command used to check disk usage information of files and directories on a computer.

the from The command has many parameter options that can be used to get the results in many formats. the from Command also displays file and directory sizes recursively.

Check disk usage of files and folders in Linux

This article explains 10 useful “you” commands with their examples that might help you figure out the size of files and directories in Linux. The information in this article is taken from the man pages for from Command.

Also read:

  • 12 “df” command to check the Linux system hard disk space
  • Agedu – A useful tool for finding wasted space in Linux

How to determine the size of a directory on Linux

1. How to find the summary of disk usage of a. out / home / tecmint Directory tree and each of its subdirectories. Enter the command as:

[[email protected]]# du  /home/tecmint

40      /home/tecmint/downloads
4       /home/tecmint/.mozilla/plugins
4       /home/tecmint/.mozilla/extensions
12      /home/tecmint/.mozilla
12      /home/tecmint/.ssh
689112  /home/tecmint/Ubuntu-12.10
689360  /home/tecmint

The output from the above command shows the number of disk blocks in the / home / tecmint Directory along with its subdirectories.

How to find the directory size in readable format

2. Use of “-H”Option with the“from“Command returns results in”Human readable format“. This means you can see the sizes in byte, kilobyteS, megabyte, Gigabytes, etc.

[[email protected]]# du -h /home/tecmint

40K     /home/tecmint/downloads
4.0K    /home/tecmint/.mozilla/plugins
4.0K    /home/tecmint/.mozilla/extensions
12K     /home/tecmint/.mozilla
12K     /home/tecmint/.ssh
673M    /home/tecmint/Ubuntu-12.10
674M    /home/tecmint

How to find the total size of a directory in Linux

3. To get a summary of the total amount of disk usage of a directory, use the option “-S” as follows.

[[email protected]]# du -sh /home/tecmint

674M    /home/tecmint

4. Using the “-a”Flag with the“from”Command shows the disk usage of all files and directories.

[[email protected]]# du -a /home/tecmint

4       /home/tecmint/.bash_logout
12      /home/tecmint/downloads/uploadprogress-1.0.3.1.tgz
24      /home/tecmint/downloads/Phpfiles-org.tar.bz2
40      /home/tecmint/downloads
12      /home/tecmint/uploadprogress-1.0.3.1.tgz
4       /home/tecmint/.mozilla/plugins
4       /home/tecmint/.mozilla/extensions
12      /home/tecmint/.mozilla
4       /home/tecmint/.bashrc
689108  /home/tecmint/Ubuntu-12.10/ubuntu-12.10-server-i386.iso
689112  /home/tecmint/Ubuntu-12.10
689360  /home/tecmint

5. Using the “-a“Flag together with”-H“Shows the disk usage of all files and folders in a human readable format. The following output is easier to understand as it shows the files in kilobyte, Megabyte, etc.

[[email protected]]# du -ah /home/tecmint

4.0K    /home/tecmint/.bash_logout
12K     /home/tecmint/downloads/uploadprogress-1.0.3.1.tgz
24K     /home/tecmint/downloads/Phpfiles-org.tar.bz2
40K     /home/tecmint/downloads
12K     /home/tecmint/uploadprogress-1.0.3.1.tgz
4.0K    /home/tecmint/.mozilla/plugins
4.0K    /home/tecmint/.mozilla/extensions
12K     /home/tecmint/.mozilla
4.0K    /home/tecmint/.bashrc
673M    /home/tecmint/Ubuntu-12.10/ubuntu-12.10-server-i386.iso
673M    /home/tecmint/Ubuntu-12.10
674M    /home/tecmint

6. Determine the disk usage of a directory tree with its subtree in kilobyte Blocks. Use the “-k”(Indicates size in 1024 Byte units).

[[email protected]]# du -k /home/tecmint
40      /home/tecmint/downloads
4       /home/tecmint/.mozilla/plugins
4       /home/tecmint/.mozilla/extensions
12      /home/tecmint/.mozilla
12      /home/tecmint/.ssh
689112  /home/tecmint/Ubuntu-12.10
689360  /home/tecmint

7. To get a summary of the disk usage of the directory tree along with its subtrees in megabyte (MB) only. Use the option “-mh“as follows. The”-m”Flag counts the blocks in MB Units and “-H“Stands for human-readable format.

[[email protected]]# du -mh /home/tecmint

40K     /home/tecmint/downloads
4.0K    /home/tecmint/.mozilla/plugins
4.0K    /home/tecmint/.mozilla/extensions
12K     /home/tecmint/.mozilla
12K     /home/tecmint/.ssh
673M    /home/tecmint/Ubuntu-12.10
674M    /home/tecmint

8. The “-C”Flag provides a total consumption of hard disk space in the last line. When your directory is full 674 MB Spaces, then the last two lines of the output would be.

[[email protected]]# du -ch /home/tecmint

40K     /home/tecmint/downloads
4.0K    /home/tecmint/.mozilla/plugins
4.0K    /home/tecmint/.mozilla/extensions
12K     /home/tecmint/.mozilla
12K     /home/tecmint/.ssh
673M    /home/tecmint/Ubuntu-12.10
674M    /home/tecmint
674M    total

How to exclude files with du Command

9. The following command calculates and displays disk usage for all files and directories, but excludes those files that match the specified pattern. The following command closes the “.TXT”Files when calculating the total size of a directory. In this way you can exclude any file format by setting the flag “–exclude“. Look at the output, there isn’t any TXT Files entry.

[[email protected]]# du -ah --exclude="*.txt" /home/tecmint

4.0K    /home/tecmint/.bash_logout
12K     /home/tecmint/downloads/uploadprogress-1.0.3.1.tgz
24K     /home/tecmint/downloads/Phpfiles-org.tar.bz2
40K     /home/tecmint/downloads
12K     /home/tecmint/uploadprogress-1.0.3.1.tgz
4.0K    /home/tecmint/.bash_history
4.0K    /home/tecmint/.bash_profile
4.0K    /home/tecmint/.mozilla/plugins
4.0K    /home/tecmint/.mozilla/extensions
12K     /home/tecmint/.mozilla
4.0K    /home/tecmint/.bashrc
24K     /home/tecmint/Phpfiles-org.tar.bz2
4.0K    /home/tecmint/geoipupdate.sh
4.0K    /home/tecmint/.zshrc
120K    /home/tecmint/goaccess-0.4.2.tar.gz.1
673M    /home/tecmint/Ubuntu-12.10/ubuntu-12.10-server-i386.iso
673M    /home/tecmint/Ubuntu-12.10
674M    /home/tecmint

How to find directory usage by modification time

10. Show disk usage based on a change in time, use the flag “-Time“As shown below.

[[email protected]]# du -ha --time /home/tecmint

4.0K    2012-10-12 22:32        /home/tecmint/.bash_logout
12K     2013-01-19 18:48        /home/tecmint/downloads/uploadprogress-1.0.3.1.tgz
24K     2013-01-19 18:48        /home/tecmint/downloads/Phpfiles-org.tar.bz2
40K     2013-01-19 18:48        /home/tecmint/downloads
12K     2013-01-19 18:32        /home/tecmint/uploadprogress-1.0.3.1.tgz
4.0K    2012-10-13 00:11        /home/tecmint/.bash_history
4.0K    2012-10-12 22:32        /home/tecmint/.bash_profile
0       2013-01-19 18:32        /home/tecmint/xyz.txt
0       2013-01-19 18:32        /home/tecmint/abc.txt
4.0K    2012-10-12 22:32        /home/tecmint/.mozilla/plugins
4.0K    2012-10-12 22:32        /home/tecmint/.mozilla/extensions
12K     2012-10-12 22:32        /home/tecmint/.mozilla
4.0K    2012-10-12 22:32        /home/tecmint/.bashrc
24K     2013-01-19 18:32        /home/tecmint/Phpfiles-org.tar.bz2
4.0K    2013-01-19 18:32        /home/tecmint/geoipupdate.sh
4.0K    2012-10-12 22:32        /home/tecmint/.zshrc
120K    2013-01-19 18:32        /home/tecmint/goaccess-0.4.2.tar.gz.1
673M    2013-01-19 18:51        /home/tecmint/Ubuntu-12.10/ubuntu-12.10-server-i386.iso
673M    2013-01-19 18:51        /home/tecmint/Ubuntu-12.10
674M    2013-01-19 18:52        /home/tecmint

Also read:

  • 10 fdisk commands for managing Linux hard drive partitions
  • Gdu – A pretty fast Disk Usage Analyzer for Linux
Tags: