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 the result of a means displays all files and folders (without subdirectories) 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

one,du 's function:' 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. second,du common options: -H: Displayed in a human-readable way -A: Displays the amount of disk space occupied by the directory, and also shows the size of the disk space under which the directory and file is being consumed- s: Displays the amount of disk space occupied by the directory, and does not display the amount of disk space the subdirectory and file occupy - C: Displays the amount of disk space occupied by several directories or files, and also counts their sums --apparent-size: Displays the size of the directory or file itself -L: Statistics hard link takes up disk space size - L: The amount of disk space the file that the statistical symbolic link points to occupies One, du-h: This is 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. Four, 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 size as itself;Linuxis unique,Windowsthe 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 theWC or ls--block-size shows its size, and du gives the size of the disk space occupied. v. 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: theCount 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 Instea D 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, thedu command does not statistically link files (either hard links or symbolic links) when the statistics directory occupies disk space, so it is indicated by the- L and- l options; In addition,du The command does not display information about the disk space used by the file in the directory by default, but it shows the disk space occupied by its subdirectory by default. 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.

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.