Use Du to view the size of a file or directory that consumes disk space under Linux

Source: Internet
Author: User

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

The du command is used to view the size of the disk space occupied by a 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 space for the   Current directory. Obviously, unlike DF, it is used to view the size of the disk space occupied by a file or directory.   du common options:-H: Display a human-readable way to show the size of the disk space occupied by the directory, and also to show the size of the disk space under which the directory and file is being used-s: Displays the amount of disk space occupied by the directory, and does not display the amount of disk space used by its subdirectories and files- C: Shows the amount of disk space occupied by several directories or files, and also the sum of their sums--apparent-size: Displays the size of the directory or file itself-l : Statistics hard links take up disk space size-L: The size of the file that the statistical symbolic link points to takes up the amount of disk space one, du&  Nbsp;-h: That's not much to say.  Du -a: When using this option, displays the directory and directory under which the subdirectories and files occupy the size of disk space.  As you can see, du only displays the size of the disk space used by the download directory by default, and with the-a option, it shows not only the directory (the last row), but also the amount of disk space that each file occupies in the directory.  Du -s: When you use this option, Du displays only the size of the disk space that the directory occupies, not the information that its subdirectories and files consume disk space.  By default, Du does not display information about the disk space used by a file in the directory, but it displays information about its subdirectory footprint, and when the-s option is used, only the size of the disk space consumed by the XX directory is displayed. Iv. du --apparent-size: Displays the size of the file or directory itself, not the amount of disk space they occupy. The size of a file or directory that occupies disk space is sometimes not exactly the same as the size of its own, which is not unique to Linux, and WindowsIn the same way. We look at the explanation of the Help document for this option: 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 an apparent size of 3. such  a small file may require anywhere from 0 to 16 kib  or more of disk space, depending on the type and   Configuration of the file system on which the file resides. This paragraph gives the difference between the size of the file or directory itself and the amount of disk space that is consumed. He has given a more exaggerated example, and it is not written here. We know that the WC or ls --block-size shows its size, and du gives the size of the disk space it occupies.   DU -C: When using this option, not only does it show how many files or directories each occupy the size of disk space, but also the sum of them.
, with the-C option, Du shows not only the size of the two directories that occupy disk space, but also the sum of them in the last line. Vi. du-l: This option is mainly for hard links. When the statistics catalog consumes disk space, the-l option also counts hard links.  The help document explains this: the Count the size of all Files,even if they has appeared already (as a hard link). We create a hard link under the download directory, pointing to a file in this directory. When you do not use the-l option, du finds a hard link to a file in this directory, and then automatically ignores the linked file to avoid duplication of statistics; with the-l option, du will also count hard-link files.

Vii. du-l: This option is primarily for symbolic links. It also counts the amount of disk space that the file that the symbolic link points to takes up.  The help document explains this: Dereference Symbolic links (show the disk space used by the file or directory, the link points to instead of The space used by the link).

We create a symbolic link under the download directory, pointing to a file in this directory.  We see the result of the action shown in the image above, 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, the same as du-h, as if there is no statistics on the size of the symbolic link;  From a practical point of view, the symbolic link itself does not seem to occupy disk space, so the above situation occurs. Finally, the du command does not statistically link files (either hard links or symbolic links) By default when the statistics catalog occupies disk space, so it is indicated by the-L and-l options, and the du command does not display the information about the disk space used by files in the directory by default, but it defaults to the disk space occupied by its subdirectory. Strange.

Du-sh: View the total capacity of the current directory. Without individually listing the capacity occupied by each subkey

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

Use Du to view the size of a file or directory that consumes disk space under Linux

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.