Viewing folder sizes with the du command

Source: Internet
Author: User
Tags disk usage
Command: Du usage linux folder size du-sh./view current directory size du-sh * View folder size in current directory du command

Use

Overview disk usage.

Grammar

Du [a | s] [k] [M] [-g] [-l] [-r] [-X] [-H | l] [File ...]

Description

The du command displays the number of blocks used for the file. If the specified file parameter is actually a directory, all files within that directory are reported. If no file argument is supplied, the du command uses the files in the current directory.

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

Specifies the-a flag, which reports the number of blocks in the individual file. The individual files specified by the file parameter are always listed, regardless of whether the-a flag is used.

Specifies the-s flag, which reports all blocks for all files in the specified file and directory.

The block count includes an indirect block for each file. The block count is computed in 512-byte units, regardless of the cluster size used by the system. Specifies the-K flag, which computes the number of blocks in 1024-byte units.

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

Sign

-a displays disk usage for each specified file, or displays the respective disk usage for each file in the directory. Compare the flag to the-s flag.
-G calculates the number of blocks in GB, rather than the default 512-byte unit. The output values for disk usage are floating-point numbers, because the value is very large if you are in bytes.
-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 calculates the number of blocks in 1024-byte units instead of the default 512-byte units.
-L distributes blocks evenly between file links and multiple links. A file with two or more links is counted only once, depending on the default value.
-L If a symbolic link is specified on the command line or a symbolic link is encountered more than once in the traversal of a file hierarchy, the du command should count the size of the file or file hierarchy referenced by the link.
-M calculates the number of blocks in megabytes, rather than the default 512-byte unit. The output values for disk usage are floating-point numbers, because the value is very large if you are in bytes. The
-R reports inaccessible files or directory names. This is the default setting.
-S displays the entire disk usage for all specified files, or displays the total disk usage for all files in a directory. Compare the flag to the-a flag.
-x evaluates file sizes by evaluating only those files that reside on the same device as the files specified by the file parameter or directories. For example, you can specify a directory that contains files on multiple devices. In this case, the-X flag displays the block size for all files that reside on the same device as the directory.

If you specify all the-K,-M, and-g flags, or any two of them, the last specified one works. Using the flag-m and-g output disks will approximate the nearest second decimal number.

Exit Status

This command returns the following export values:

0 Successful end.
>0 An error has occurred.

example to outline the disk usage of a directory tree and each of its subtrees, enter:

Du/home/fran

This displays the number of disk blocks in the/home/fran directory and each of its subdirectories. To summarize the disk usage of a directory tree and its subtree through a 1024-byte block, enter:

Du-k/home/fran
This shows the number of 1024-byte disk blocks in the/home/fran directory and each of its subdirectories. To summarize the disk usage of a directory tree and its subtree by using a MB disk block, enter:
Du-m/home/fran
This shows the number of MB disk blocks (approximate to the nearest second decimal number) in the/home/fran directory and each of its subdirectories. To summarize the disk usage of a directory tree and each of its subtrees through a GB block, enter:
Du-g/home/fran
This displays the number of GB disk blocks (approximate to the nearest second decimal number) in the/home/fran directory and each of its subdirectories. To display disk usage for each file, enter:
Du  -a/home/fran
This shows the number of disk blocks contained in each file and in the subdirectory of the directory/home/fran. The number next to the directory is the disk usage of the directory tree. The number next to the regular file is the individual disk usage of the file. To display all disk usage for only one directory tree, enter:
Du  -s/home/fran
The-S flag controls the du command, showing only the sum of the disk usage of the/home/fran directory and the files contained therein. By default, if the du command cannot read a file or directory, an error message is displayed. In addition to the regular files found in the/home/fran traversal, and to display the disk use of all the file or file hierarchies referenced by all symbolic links, enter:
Du-l/home/fran
To report disk use of a file or file hierarchy referenced by a symbolic link mylink, enter:
Du-h MyLink

file

/usr/bin/du Contains command du.

Related Information

DF command.

The "Directory Overview" in the AIX 5L V5.2 System User's Guide: Operating systems and devices explains the handling of directory and path names.

The "File Overview" in the AIX 5L V5.2 System User's Guide: Operating systems and devices provides information for working with files.

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.