Linux use du to view the size of a file or directory that occupies disk space method _linux

Source: Internet
Author: User

Du-ah--max-depth=1 This is what I want. A indicates that all files and folders (excluding subdirectories) are displayed in the directory, and H means that the max-depth represents the depth of the directory in a way that humans can read.

The du command is used to view the size of the disk space occupied by the directory or file. Common option combinations are: Du-sh

the function of du:' du ' reports the amount of disk space used by the specified files and for each subdirectory (of directory arguments). With no arguments, ' du ' reports the disk spaces for the current directory.

Obviously, unlike DF, it is used to view the size of the disk space occupied by a file or directory.

Second, du commonly used options:

-H: Display in a human-readable way

-A: Displays the amount of disk space occupied by the directory, as well as the size of the disk space under which the directories and files are occupied

-S: Displays the amount of disk space occupied by the directory and does not show the size of the disk space occupied by its subdirectories and files

-C: Displays the amount of disk space occupied by several directories or files, and counts the sum of them

--apparent-size: Displays the size of the directory or file itself

-L: Statistics the size of hard links taking up disk space

-L: Statistics The amount of disk space that the file pointed to by the symbol link occupies

One, du-h: This is not much to say.

Second, Du-a: When using this option, display directory and directory subdirectories and files occupy the size of disk space.

As you can see, by default, du only shows the size of the disk space occupied by the download directory, and with the-a option, it shows not only the directory (last row), but also the size of the individual files under the directory that occupy the disk space.

Du-s: When you use this option, Du displays only the size of the disk space occupied by the directory, and does not display information about the disk space occupied by its subdirectories and files.

By default, Du does not display information about disk space consumed by files in the directory, but it displays information about the disk space occupied by its subdirectories, and the-S option shows only the size of the disk space occupied by the XX directory.

du--apparent-size: Displays the size of the file or directory itself, rather than the amount of disk space they occupy. The size of a file or directory that consumes disk space is sometimes not exactly the same size as they are, and is not unique to Linux, as it is in Windows. We look at the explanation of this option's Help document: The apparent size of a file is the number of bytes reported by ' wc–c ' regular files, or more generally, ' Ls–l–block-size=1 ' or ' stat–format=%s '. For example, a file containing the word ' zoo ' with no newline would, of course, have a apparent size of 3. Such a small file may require anywhere from 0 to KiB or more of disk spaces, depending on the type and configuration of The file system on which the file resides.

This passage gives a distinction between the size of the file or directory itself and the size of the disk space. He gives an even more exaggerated example here, and does not write it down here. We know: the WC or LS--block-size displays its own size, while du gives the amount of disk space occupied.

DU-C: When you use this option, you will not only show how many files or directories each occupy the size of the disk space, but also count their totals.

As shown in the figure, with the-C option, Du shows not only the size of the two directories that occupy the disk space, but also the sum of them on the last line.

VI, DU-L: This option is mainly for hard links. the-l option also counts hard links when the statistics directory occupies disk space size. The help document explains this: Count the size of all Files,even if they have appeared already (as a hard link).

We set up a hard link in the download directory, pointing to a file under this directory. When the-l option is not used, Du discovers that a hard link points to a file in this directory and automatically ignores the linked file so that it does not result in duplicate statistics; using the-l option, du will also count the hard link files.

Seven, du-l: This option is mainly for symbolic links. It will also count the size of the disk space that the symbol link points to in the file. This is explained by the Help document: Dereference Symbolic links (show the disk spaces used by the file or directory this link points to instead of The space is used by the link.

We create a symbolic link in the download directory that points to a file in this directory. We see the results of the operation shown in the above picture, and when the-l option is used, Du will also count the size of the file that the symbolic link points to in the directory.

In addition, we look at the results of DU-LH, and the same as the du-h, as if not statistically the size of the symbolic link; From the actual point of view, the symbolic link itself does not seem to occupy disk space, so this situation occurs.

Finally, when the du command takes up disk space in the statistics directory, the default does not count link files (either hard links or symbolic links), so it is specifically indicated with the-L and-l options; In addition, the DU command does not display information about disk space in the directory by default, but it displays information about the disk space occupied by its subdirectories. Strange.

Du-sh: View the total capacity of the current directory. Rather than list the capacity occupied by each subkey separately

DU-LH--max-depth=1: View the disk capacity occupied by the next level of child files and subdirectories in the current directory.

Above this Linux use Du to view a file or directory to occupy the size of the disk space method is small to share all the content of everyone, hope to give you a reference, but also hope that we support cloud habitat community.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.