Run the du command to view the folder size.

Source: Internet
Author: User
Tags disk usage
Command: du usage Linux folder size Du-Sh./view the current directory size Du-sh * view the folder size DU in the current directory command

Purpose

This topic describes how to use a disk.

Syntax

Du [
-A |
-S] [
-K] [
-M] [
-G] [
-L] [
-R] [
-X] [
-H |
-L] [
File...]

Description

The du command shows the number of blocks used for files. If the specified file parameter is actually a directory, all files in the directory should be reported. If the file parameter is not provided, the du command uses the files in the current directory.

If the file parameter is a directory, the number of reported blocks is the sum of the blocks allocated to and allocated to the directory.

Specify the-a flag to report the number of blocks in the individual file. Whether or not the-a flag is used, the individual files specified by the file parameter are always listed.

Specifies the-s flag. The report is used for all blocks of all files in the specified file and directory.

The block count includes the indirect blocks of each file. The block count is calculated in 512 bytes and is irrelevant to the cluster size used by the system. Specify the-K flag and calculate the number of blocks in 1024 bytes.

Note:
  1. Files with multiple links are counted and written only for one entry.
  2. Because the block count is only based on the file size, unallocated blocks are not included in the number of reported blocks.
  3. If du cannot get the file attribute or cannot read the directory, it reports an error and affects the exit status of the command.

Flag

 

- Displays the disk usage for each specified file or the disk usage for each file in the directory. Compare the flag with the-s flag.
-G The number of blocks is calculated in the unit of GB, instead of the default 512 bytes. The output value of disk usage should be a floating point number, because if bytes are used, the value will be very large.
-H If a symbolic link is specified on the command line, the du command counts the size of the file or File hierarchy referenced by the link.
-K The number of blocks is calculated in 1024 bytes, rather than the default 512 bytes.
-L Evenly allocate blocks between file links and multiple links. Based on the default value, files with two or more links are counted only once.
-L If you have specified a symbolic link in the command line or encounter a symbolic link multiple times during File hierarchy traversal, The du command should count the size of the file or File hierarchy referenced by the link.
-M Calculate the number of blocks in MB instead of the default 512 bytes. The output value of disk usage should be a floating point number, because if bytes are used, the value will be very large.
-R Report files or directories that are inaccessible. This is the default setting.
-S Displays the usage of the entire disk for all specified files, or displays the total disk usage for all files in a directory. Compare the flag with the-a flag.
-X When the evaluation file size is large, only files or directories specified with the file parameter reside on the same device are evaluated. For example, you can specify a directory that contains files on multiple devices. In this case, the-X mark shows the block size for all files that reside on the same device as the directory.

If all-K,-M, and-G are specified, or any two of them are specified, the last one takes effect. The usage of the flags-M and-G output disks is approximately the nearest second decimal number.

Exit status

This command returns the following export values:

0 Ended successfully.
> 0 An error occurred.

Example
  1. To outline the disk usage of a directory tree and each subtree, enter:

     

    du /home/fran

    In/Home/FranThe directory and Its subdirectories show the number of disk blocks.

  2. To use 1024 bytes to describe the disk usage of a directory tree and each subtree, enter:
    du -k /home/fran

    The/home/Fran directory and each of its subdirectories show 1024 bytes of disk size.

  3. To use MB disk blocks to describe the disk usage of a directory tree and each subtree, enter:
    du -m /home/fran

    This shows the number of MB disk blocks in the/home/Fran directory and each sub-directory (approximate to the nearest second decimal number ).

  4. To use GB blocks to describe the disk usage of a directory tree and each subtree, enter:
    du -g /home/fran

    This shows the number of GB disk blocks in the/home/Fran directory and each subdirectory (approximate to the nearest second decimal number ).

  5. To display the disk usage of each file, enter:
    du  -a /home/fran

    This shows the contents of each file and directory./Home/FranThe number of disk blocks in the subdirectory. The number next to the directory is the disk usage of the directory tree. The number next to a regular file is the independent disk usage of the file.

  6. To display only the disk usage of a directory tree, enter:
    du  -s /home/fran

    -S flag controls the du command, only display/Home/FranThe total disk usage of the Directory and the files contained in it. By default, if the du command cannot read a file or directory, an error message is displayed.

  7. Besides/Home/FranThe regular files found in the traversal, and the disk usage of all file or file hierarchies referenced by symbolic links are also displayed. Enter:
    du -L /home/fran
  8. Link to report symbolsMylinkFor disk usage of referenced files or file hierarchies, enter:
    du -H mylink

File

 

/Usr/bin/du Contains the command du.

Related information

DF command.

The "Directory Overview" in "Aix 5l v5.2 System User Guide: operating systems and devices" explains how to process directory and path names.

"File overview" in "Aix 5l v5.2 System User Guide: operating systems and devices" provides information for file processing.

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.