Shell File Size calculation

Source: Internet
Author: User
Tags disk usage

Du simple Usage example
Du-SH xmldb/Du-Sm* |  sort -n //statistics current directory size and size sorting du -sk *|  sort -ndu -sk * | grep guojf //look at a person's size du -m | cut  -d  "/"  -f 2 //See text before second/character         

See how many files are in this folder * How many files are there?

Du xmldb/du xmldb*|  -l     

Output:40752

Explanation: WC [-LMW]

Parameter description:

-L: How many lines
-M: How many characters
-W: how many words

The du command explains in detail:

Du:disk usage abbreviation, the command function is the size of the disk space that the display directory (or file) occupies.

Syntax

Du[-AbcDhHklmsSx0] [-l][-x file][--block-size< Span class= "pun" >=size][--exclude=pattern] [--max -depth=n][-- help][--version][ File-or-path]    

Parameter description:

  • -0 No newline after each result display

  • -A or –all displays disk usage for each specified file, or displays the respective disk usage for each file in the directory.

  • –apparent-size display the size of the directory or file itself

  • -B or –block-size=size displays the directory or file size in size as a unit of measure; size can be any integer or KB, K, MB,M1024, similarly to G, T, P, E , Z, Y.

  • -B or –bytes displays the directory or file size in bytes, equivalent to ' –apparent-size–block-size=1′

  • -C or –total displays the sum of all directories or files in addition to the size of the directory or file.

  • -D or –dereference-args displays the source file size for the specified symbolic connection.

  • –FILES0-FROM=F Displays the disk space occupied by the file name ending with nul in the files F, and if the value of F is "-", the file name is read from the standard input

  • -H or –human-readable in k,m,g to improve the readability of the information.

  • -H or –si is the same as the-h parameter, but K,m,g is converted to 1000 units instead of 1024.

  • -K or –kilobytes in bytes units equivalent to –block-size=1k.

  • -L or –count-links repeatedly computes hard-connected files.

  • -L or –dereference statistics symbol connection source file size.

  • -P or –no-dereference the size of the source file for different symbolic links, default.

  • -M or –megabytes in 1MB, equivalent to –block-size=1m.

  • -S or –summarize displays only totals, that is, the size of the current directory.

  • -S or –separate-dirs displays the size of each directory without the size of its subdirectories.

  • -X or –one-file-system ignores directories located on other file systems.

  • -x file or –exclude-from=file ignores the directory or file specified in the file.

  • –exclude=pattern ignores a directory or file that conforms to the PATTERN rule.

  • –max-depth=n only displays the directory size within the N-tier, –max-depth=0 equals –summarize.

  • –time Displays the last modified time of a file in a directory or subdirectory.

  • –time=word the time specified in Word instead of the modified time; word takes a value atime, access, use, CTime, one of the status.

  • –time-style=style displays the time in the format specified by style, and the style takes one of the values Full-iso, Long-iso, ISO, +format, where format is the same as the date command.

  • Help Display Help.

  • –version Displays version information.

More examples of du usages:

1. To display disk usage for a directory tree and every subtree

/Home/linux  

This shows the number of disk blocks in the/home/linux directory and each of its subdirectories.

2. To display the disk usage of a directory tree and each of its subtrees in 1024-byte units

-/home/linux   

This shows the number of 1024-byte disk blocks in the/home/linux directory and each of its subdirectories.

3. Displays the disk usage of one directory tree and each subtree in megabytes

Du-m/home/linux

This shows the number of MB disk blocks in the/home/linux directory and each of its subdirectories.

4. Displays the disk usage of a directory tree and each subtree in gigabytes

Du-g/home/linux

This displays the number of GB disk blocks in the/home/linux directory and each of its subdirectories.

5. View the size of all directories and subdirectories in the current directory:

-.

“.” Represents the current directory. can also be replaced by a clear path

-H denotes an easy-to-understand unit with K, M, G displayed

6. Look at the size of the user directory under the current directory, and do not want to see other directories and their subdirectories:

Du-sh User

-S means that a summary value is listed only

Du-h–max-depth=0 User

–max-depth=n means that only deep into the nth-level directory, where set to 0, means not to go deep into subdirectories.

7. List the size of all directories and files under the user directory and its subdirectories:

-AH user

-a means including directories and files

8. List the size of the directory in the current directory that does not include the XYZ string:

Du-h–exclude= ' *xyz* '

9, want to have more information about the user directory and subdirectory size on one screen:

du-0h User

0 (bar 0) indicates the information for each directory listed, not wrapping, but outputting the information of the next directory directly.

10. Show all disk usage of only one directory tree

Shell File Size calculation

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.