Use du du lower use under [reprint] linux to view a file or directory disk space occupied by the size of linux view the size of a file or directory disk space occupied

Use the linux du View the size of a file or directory disk space occupied

 
-ah --max-depth = du 1    

last year, used once then forget .. Practice makes perfect command of this thing .. 

HTTPS: // www.cnblogs.com/kobe8/p/3825461.html

 

du -ah --max-depth = 1 this is what I want results indicate a directory display all files and folders (and sub-folders), h expressed in human can understand manner, max-depth representing the directory depth.

du command to display a directory or file size of disk space occupied. Common combinations of options as: du -sh

  一、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, with different df, which is used to view the size of files or directories take up more disk space.
  Two, du commonly used options:
  -h: displays a human-readable manner
  -a: Displays the directory of disk space occupied, but also to show its directory and files take up disk space size
  -s: display disk space occupied by the directory, do not display the size of its disk space occupied by files and subdirectories
  -c: display disk space occupied by several directories or files, but also the sum of their statistics
  --apparent-size: Display files or their size
  -l: Statistical hard disk space size occupied Links
  -L: Statistics symbolic link points to files take up disk space
  A, du -h: this is not to say.
  Two, du -a: Use this option to display the subdirectories and files take up disk space, directory size and directory.
  As can be seen, by default, only shows the size of the download directory du disk space occupied, but after using the -a option, which not only shows the directory (last line), but also shows the various files take up disk space, directory size.
  Three, du -s: When using this option, du displays only the size of the disk space occupied by the directory, without displaying the information at its subdirectories and files take up disk space.
  By default, du directory does not display files take up disk space information, but it will display information about its subdirectories take up disk space; and later use the -s option, only xx amount of disk space occupied by directories.
  Four, du --apparent-size: the size of the file or directory itself, rather than the disk space they occupy. The size of the file or directory disk space occupied size itself is not entirely consistent with their sometimes; this phenomenon unique to non-linux, windows inside as well. We see the help documentation to explain 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 passage gives the difference between the size of the file or directory itself and take up disk space size. He cited the example below a more exaggerated, here is not to write about the. We know: wc or ls --block-size shows the size of its own, while du is given by the size of the amount of disk space.
  Five, du -c: When using this option, not only shows a few occupied by each file or directory size disk space, but also the sum of their statistics.

As shown, together with the -c option, du not only display two directories respective amount of disk space occupied, they are also the last line of statistical sum.
  Six, du -l: This option is mainly for hard links. When statistical directory disk space occupied, -l option hard links will also come in statistics. Help documentation is explained: Count the size of all files, even if they have appeared already (as a hard link).
  We establish a hard link in the download directory, point to a file in the catalog. When not in use the -l option, du find hard links to files in this directory, then automatically ignore the link file in order to avoid double-counting; -l option, du will put the hard-linked files also come in statistics.

  Seven, du -L: This option is mainly for symbolic links. It would symbolic link points to a file size of disk space occupied statistics also come. Help documentation is explained this way: Dereference symbolic links (show the disk space used by the file or directory that the link points to instead of the space used by the link).

   We create a symbolic link in the download directory, point to a file in the catalog. We see the result of the operation shown in the picture above, when using the -L option, du will symbolic link points to the size of the file to the directory where the statistics come.
  In addition, we see the results du -lh of the du -h same as if there were no statistics of the size of the symbolic link; in fact not the case. From the practical point of view, the symbolic link itself does not seem to take up disk space, so it appears the situation.
  Finally, du command in the directory disk space occupied statistics, statistical link does not default file (either a hard link or a symbolic link), so use the -l and -L options specifically point out; in addition, du command does not display the default directory information files take up disk space, but the default display information about disk space occupied by its subdirectories. Guaizai.

 

du -sh: View the current directory accounted for a total capacity. Without listing each child occupied capacity alone 

du -lh --max-depth=1 : 查看当前目录下一级子文件和子目录占用的磁盘容量。

du -ah --max-depth=1     这个是我想要的结果  a表示显示目录下所有的文件和文件夹(不含子目录),h表示以人类能看懂的方式,max-depth表示目录的深度。

du命令用来查看目录或文件所占用磁盘空间的大小。常用选项组合为:du -sh

  一、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。
  很明显,与df不同,它用来查看文件或目录所占用的磁盘空间的大小。
  二、du常用的选项:
  -h:以人类可读的方式显示
  -a:显示目录占用的磁盘空间大小,还要显示其下目录和文件占用磁盘空间的大小
  -s:显示目录占用的磁盘空间大小,不要显示其下子目录和文件占用的磁盘空间大小
  -c:显示几个目录或文件占用的磁盘空间大小,还要统计它们的总和
  --apparent-size:显示目录或文件自身的大小
  -l :统计硬链接占用磁盘空间的大小
  -L:统计符号链接所指向的文件占用的磁盘空间大小
  一、du -h:这个就不多说了。
  二、du -a:使用此选项时,显示目录和目录下子目录和文件占用磁盘空间的大小。
  可以看出,默认情况下du只显示download目录占用磁盘空间的大小,而使用-a选项后,它不仅显示了目录(最后一行),而且显示了目录下各个文件占用磁盘空间的大小。
  三、du -s:使用此选项时,du只显示目录所占用磁盘空间的大小,而不显示其下子目录和文件占用磁盘空间的信息。
  默认情况下,du不显示目录下文件占用磁盘空间的信息,但它会显示其下子目录占用磁盘空间的信息;而使用-s选项以后,只显示xx目录占用磁盘空间的大小。
  四、du --apparent-size:显示文件或目录自身大小,而不是它们占用的磁盘空间大小。文件或目录占用磁盘空间的大小与它们自身大小有时候并非完全一致;这种现象非linux所独有,windows里也是如此。我们看这个选项的帮助文档的解释: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.
  这段话给出了文件或目录自身大小与占用磁盘空间大小的区别。他下面举出了一个更加夸张的例子,这里就不把它写出来了。我们知道了:wc或ls --block-size显示的是其自身大小,而du给出的则是占用的磁盘空间的大小。
  五、du -c:使用此选项时,不仅显示几个文件或目录各自占用磁盘空间的大小,还统计它们的总和。

如图所示,加上-c选项后,du不仅显示两个目录各自占用磁盘空间的大小,还在最后一行统计它们的总和。
  六、du -l:这个选项主要是针对硬链接。在统计目录占用磁盘空间大小时,-l选项会把硬链接也统计进来。帮助文档是这样解释的:Count the size of all files,even if they have appeared already(as a hard link)。
  我们在download目录下建立一个硬链接,指向本目录下的一个文件。不使用-l选项时,du发现硬链接指向本目录下的文件,于是自动忽略该链接文件,以免造成重复统计;使用-l选项,du才会把硬链接文件也统计进来。

  七、du -L:这个选项主要是针对符号链接。它会把符号链接所指向的文件占用磁盘空间的大小也统计进来。帮助文档是这样解释的:Dereference symbolic links(show the disk space used by the file or directory that the link points to instead of the space used by the link)。

   我们在download目录下创建一个符号链接,指向本目录下的一个文件。我们看到上面图片中显示的操作结果,当使用-L选项时,du会把符号链接所指向的文件的大小也统计到目录里来。
  另外我们看du -lh的结果,与du -h相同,好像没有统计出符号链接的大小;其实并非如此。从实际操作来看,符号链接本身似乎并不占用磁盘空间,所以才出现上述情况。
  最后,du命令在统计目录占用磁盘空间时,默认不统计链接文件(无论是硬链接或是符号链接),所以要用-l和-L选项特地指出来;此外,du命令默认不显示目录下文件占用磁盘空间的信息,但是却默认显示其下子目录所占用磁盘空间的信息。怪哉。

 

du -sh : 查看当前目录总共占的容量。而不单独列出各子项占用的容量 

du -lh --max-depth=1 : 查看当前目录下一级子文件和子目录占用的磁盘容量。

Guess you like

Origin www.cnblogs.com/jinanxiaolaohu/p/11120340.html