Check the folder size and total number of statistics in Linux.

Source: Internet
Author: User
Tags disk usage
Document directory
  • From javaeye
From javaeye statistics total size

Du-SH xmldb/

Du-Sm * | sort-N // count the current directory size and sort the directory size.

Du-SK * | sort-n

Du-SK * | grep guojf // view the size of a person

Du-M | cut-d "/"-F 2 // read the text before the second character

View the number of files in this folder * Number of Files

Du xmldb/

Du xmldb * | WC-l

40752

Explanation:

WC [-LMW]

Parameter description:

-L: number of rows

-M: The number of characters.

-W: How many words

Du 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:
Files with multiple links are counted and written only for one entry.
Because the block count is only based on the file size, unallocated blocks are not included in the number of reported blocks.
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

-A 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 calculates the number of blocks in 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 in 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 bytes instead of 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 calculates 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: indicates the name of an inaccessible file or directory. 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 only evaluates files that reside on the same device as the files or directories specified by the file parameter when the file size is large. 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 ends successfully.
> 0 error.

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

DU/home/Fran shows the number of disk blocks in the/home/Fran directory and Its subdirectories.

To use 1024 bytes to describe the disk usage of a directory tree and each subtree, enter:
Du-k/home/Fran shows 1024 bytes of disk space in the/home/Fran directory and Its subdirectories.
To use MB disk blocks to describe the disk usage of a directory tree and each subtree, enter:
Du-M/home/Fran shows the number of MB disk blocks in the/home/Fran directory and each of its subdirectories (approximate to the nearest second digit in decimal format ).
To use GB blocks to describe the disk usage of a directory tree and each subtree, enter:
Du-g/home/Fran shows the number of GB disk blocks in the/home/Fran directory and each of its subdirectories (approximate to the nearest second digit in decimal format ).
To display the disk usage of each file, enter:
Du-A/home/Fran shows the number of disk blocks contained in each file and subdirectory/home/Fran. 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.
To display only the disk usage of a directory tree, enter:
The Du-S/home/Fran-s flag controls the du command and only displays the total disk usage of the/home/Fran directory and the files contained in it. 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 traversal of/home/Fran, you must also display the usage of all files referenced by symbolic links or file hierarchies on disks. Enter:
Du-L/home/Fran:
Du-H mylink
File

/Usr/bin/du contains the command du.

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.