The file parameter is actually a directory that reports all the files in that directory. If the file parameter is not provided, the DU command uses the files in the current directory.
If the file parameter is a directory, then the number of reported blocks is the sum of the blocks allocated to the directory and to the directory itself.
Specify the-a flag to report the number of blocks in the individual file. The individual files specified by the file parameter are always listed, regardless of whether the-a flag is used or not.
Specifies the-s flag, which reports all blocks of all files in the specified file and directory.
The block count includes an indirect block for each file. The block count is calculated in 512-byte units, regardless of the cluster size used by the system. Specifies the-K flag, which calculates the number of blocks in 1024-byte units.
Cases:
To summarize disk usage for a directory tree and each of its subtrees, enter:
Du/home/fran
This shows the number of disk blocks in the/home/fran directory and each of its subdirectories.
To summarize disk usage for a directory tree and each of its subtrees with 1024-byte blocks, enter:
Du-k/home/fran
This shows the number of 1024-byte disk blocks in the/home/fran directory and each of its subdirectories.
To summarize disk usage for one directory tree and each of its subtrees through MB disk blocks, enter:
Du-m/home/fran
This shows the number of MB disk blocks (approximately the nearest second decimal number) in the/home/fran directory and each of its subdirectories.
To summarize the disk usage of one directory tree and each of its subtrees with GB blocks, enter:
Du-g/home/fran
This displays the number of GB disk blocks (approximately to the nearest second decimal number) in the/home/fran directory and each of its subdirectories.
To display each file disk usage, enter:
Du-a/home/fran
This shows the number of disk blocks contained in each file and in the subdirectory of the directory/home/fran. The number next to the directory is the disk usage of the directory tree. The number next to the regular file is the separate disk usage for that file.
To view file and folder sizes:
Du–sh dirname
If you look at the size of all files and files in a directory:
Du–sh *
For example:
Du-sh opt
Sort by file size
Du–sh * |sort–n
Linux view the size of folders and files in the current directory