Linux du – find disk usage of directories or files

Linux du command can be used to find disk usage of files and directories. Here are some handy du commands on Ubuntu Linux (or any other Linux).

Find disk usage in block size

Find disk usage of file or directory (in –block-size, default is 1K usually). It is usually larger that actual file size.

$ du 10K_file1.out 

disk usage in human readable format

$ du -h 10K_file1.out 
12K	10K_file1.out

Find apparent disk usage

Print apparent sizes, rather than disk usage. The apparent size is usually smaller, but it may be larger due to holes in sparse files.

Smaller apparent size case:

$ du --apparent-size -h 10K_file1.out
10K	10K_file1.out
Larger apparent size case:
$ truncate --size 1M 1M_file_created_using_truncate.out
$ du -h 1M_file_created_using_truncate.out
0	1M_file_created_using_truncate.out
$ du --apparent-size -h 1M_file_created_using_truncate.out
1.0M	1M_file_created_using_truncate.out

Display count for all files

To display count of all files (inside directories):

$ du --all dir1
0	dir1/large
10240	dir1/file2.out
10244	dir1
Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit


Click here to write/view comments