“du” – short form for “Disk Usage” is a command used by Linux users to estimate/identify the file space usage.
By default “du” command summarizes the disk usage for all the files and directories present from where you have executed “du” command recursively. i.e. if you type “du” in workspace directory which again has some files and directories then, it will display a list of all the files along with their respective sizes. By default, size given is in kilobytes.
Syntax: du [option]
Some Options Using in “du” command:
-a, –all : write count of all files, not just directories
–apparent-size : print apparent sizes, rather than disk usage.
-B, –block-size=SIZE : scale sizes to SIZE before printing on console
-c, –total : produce grand total
-d, –max-depth=N : print total for directory only if it is N or fewer levels below command line argument
-h, –human-readable : print sizes in human readable format
-S, -separate-dirs : for directories, don’t include size of subdirectories
-s, –summarize : display only total for each directory
–time : show time of last modification of any file or directory.
–exclude=PATTERN : exclude files that match PATTERN
$ cd workspace
$ du 13248 ./helloworld.pdf 42064 ./hello_dir/helloworld.c
Now, if we see the same files sizes in human readable format using “-h” option, those will be seen as,
$ du -h 13M ./helloworld.pdf 42M ./hello_dir/helloworld.c
There is one more similar command as “df” . Don’t confuse “du” with “df” .
“df” which prints information about the disk usage of the mounted file system , whereas
du command gives you estimate of disk space used by given files or directories.
You can view all available
du command options by typing
man du in your terminal.