Linux du command usage Detailed

du command is the estimated amount of disk space "disk usage" abbreviation, specify the output file or directory to use. It is useful to look up a lot of disk space for files and directories.

How to use the du command

du general syntax of the command is as follows:

du [OPTIONS]... FILE...

If a given FILE is a directory, du will be in the directory disk usage of each file and subdirectory summary. If FILE is not specified, du then the current working directory of the disk usage report.

When executed without any options du circumstances, it will be shown in bytes of a given file or directory and its subdirectories for each disk usage.

the ~ / Documents

You can also multiple files and directories passed as a parameter to the du command:

du ~/Documents ~/Pictures ~/.zshrc

If you run the du command of files and directories that you do not have permission to a file or directory, it appears similar to: Content "du can not read directory" of. In this case, you need to add sudo before the command.

du There are many options, we will outline the most common options.

du -a option tells you to report the disk space for each file in the directory usage.

du -a ~ / Documents

Typically, you want a human-readable format to display only the space occupied by the given directory. To do this, use the -h option.

For example, to obtain the / var / lib total size of its subdirectories and all subdirectories, run the following command:

sudo you -h / var / lib

We used sudo, because most of the files and directories in / var / lib directory owned by the root user and ordinary users can not read. The output looks like this:

...
4.0K /var/lib/apt/mirrors/partial
8.0K /var/lib/apt/mirrors
205M /var/lib/apt
2.9G /var/lib/

To output only the total size of the specified directory, not a subdirectory of the total size of the output, use the -s option:

sudo you -SH / was

2.9G / was

-c option tells du report totals. When you want to get a combination of two or more the size of a directory, which is very useful.

sudo you -csh / var / log / var / lib

1.2G /var/log
2.9G /var/lib
4.1G total

If you want to display disk usage n-level subdirectory, use the --max-depth option and specify the subdirectory level. For example, to obtain a report on the first level of the directory you will use:

sudo you -h --max-depth = 1 / var / lib

...
544K /var/lib/usbutils
4.0K /var/lib/acpi-support
205M /var/lib/apt
2.9G /var/lib

The default behavior is du utility regain the disk space used by the file or directory. To find the file "apparent size", use --apparent-size switch. "Apparent size" is the amount of file data in the file actually exists.

sudo du -sh --apparent-size /var/lib

2.9G / var / lib

du also allows you to use shell mode. For example, to get the size of all directories to "Do" in the beginning of the home directory, you would run:

sudo du -csh ~/Do*

102M /home/linuxize/Documents
358M /home/linuxize/Downloads
460M total

Using du with other commands

du command may be combined with other commands in the pipeline.

For example, to print the / var directory five largest directory, you can pass du output to the sort command, the size of the directory to its sort, and then outputs an output command to print only the front head 5 via conduit directory :

sudo you -h / var / | black -RH | Head -5

4.6G /var/
2.9G /var/lib
2.6G /var/lib/snapd
1.7G /var/lib/snapd/snaps
1.2G /var/log/journal/af8ce1d394b844fea8c19ea5c6a9bd09

to sum up

By now, you should have a good understanding of how to use the du command.

And different df, df print information about installing the file system disk usage, the du command can estimate given disk space used by the file or directory.

You can by typing man du in terminal to see all available du command options.

Guess you like

Origin www.linuxidc.com/Linux/2019-08/159914.htm