One day a shell command Linux good housekeeper-disk-DU command detailed _linux Shell

Source: Internet
Author: User
Tags readable disk usage

Du command

Disk Management

The du command also looks at the usage space, but unlike the DF command, the Linux du command is a view of the space used by files and directory disks, or there are some differences from the DF command.

Grammar

du [Options] [file]

Options

A or-all displays the size of individual files in the directory.
-B or-bytes displays the directory or file size in bytes.
-C or--total displays the sum of all directories or files in addition to the size of individual directories or files.
-K or--kilobytes is output in kilobytes (1024bytes).
-M or--megabytes is output in MB.
-S or--summarize only displays totals, listing only the last plus total value.
-H or--human-readable to k,m,g to improve the readability of the information.
-X or--one-file-xystem the file system at the start of the process, and if you encounter a different file system directory, skip.
-l< the source file size of the symbolic link specified in the symbol link > or--dereference< symbol link > Display option.
When-S or--separate-dirs displays the size of an individual directory, it does not contain the size of its subdirectories.
-x< files > or--exclude-from=< files > specify directories or files in < file >.
--exclude=< directory or File > skips the specified directory or file.
-D or--dereference-args displays the source file size for the specified symbolic link.
The-H or--si is the same as the-h parameter, but K,m,g is a unit of conversion in 1000.
-L or--count-links a file that duplicates the hardware link.

Instance

1, display the directory or file space occupied:

[Root@localhost test]# du
608/test6
308./test4
4/scf/lib
4./scf/service/deploy/product
4./ Scf/service/deploy/info
/scf/service/deploy
/scf/service
4/scf/doc
4/scf/bin
32./ SCF
8/test3
1288.

2. Displays only the directory size of the subdirectory below the current directory and the total size of the current directory, and the bottom 1288 is the total size of the current directory

To display the space occupied by the specified file:

Copy Code code as follows:

[Root@localhost test]# du Log2012.log
Log2012.log

3. View the space occupied by the specified directory:

[Root@localhost test]# du SCF
4 scf/lib
4 scf/service/deploy/product
4 scf/service/deploy/info
Scf/service/deploy
scf/service
4 scf/doc
4 scf/bin
SCF

4, show the space occupied by multiple files:

[Root@localhost test]# du log30.tar.gz log31.tar.gz
4 log30.tar.gz
4 log31.tar.gz

shows only the size of the sum:
[ Root@localhost test]# du-s
1288.

[Root@localhost test]# du-s scf scf

[root@localhost test]# CD.
[root@localhost soft]# du-s test
1288 test

Here are some additional information from the scholar:

Description

Du is the abbreviation for disk usage, which is used to summarize the size of each file and to count multiple files

Related commands

Df

Simple example

I created two files.

Copy Code code as follows:

$du--help>du.txt
$man du > Mandu.txt

1. View File size

$du Du.txt Mandu.txt

As shown in figure:

Explanation: Print both the Du.txt and Mandu.txt sizes (the default unit is byte bytes)

2. View the file size in a directory,
$du –a tmp/

As shown in figure:

Explanation: tmp/is the directory size of 84 bits

3. Statistics of the size of several documents
$du –c du.txt Mandu.txt

help of Du

Usage: du [options] ... [File] ...
Or: du [options] ...--files0-from=f
Summarize the amount of disk used in each < file >, and take the total amount of the catalogue.

Parameters that must be used with long options are also required when using short options.

Description
-A,--all print all files, including directories
--apparent-size prints the size of the visible content, which is more accurate than the du command. Although apparent size is usually smaller, it may be larger than du because of hard disk fragmentation, etc.
-B,--block-size=size User defined units (b,k,m)
-B,--bytes unit 1byte equivalent to '--apparent-size--block-size=1 '
-C,--total statistic size
-D,--dereference-args dereference files that are symbolic links for soft connection file
--files0-from=f statistics file size, the statistics file file to end with Nul, and in the file F specified name
-H Unit 1000 instead of 1024; equivalent to--dereference-args (-D)
-H,--human-readable print (e.g, 1K 234M 2G) in a readable manner
--si like-h, but use powers of 1000 not 1024
-K like--block-size=1k
-L,--count-links statistics multiple times if it's a hard link
-M like--block-size=1m
-L,--dereference view all soft connections
-P,--no-dereference does not view soft connection files (default)
-0, (here is "0")--null each output line replaces the new row with 0 bytes (while outputting multiple files, one line)
-S,--separate-dirs does not include subdirectory size
-S,--summarize shows only the total size (-c) There will be some other statistics here.
-X,--one-file-system skips other file system branches
-x file,--exclude-from=file excludes files that match the regular expression file.
--exclude=pattern exclude files that match pattern.
--max-depth=n Print all files (or files,--all with commands) in the directory, only the directory depth is less than equal to the parameter command N; --max-depth=0 is equal to--summarize.
--time Displays the last modification time for all files, including subdirectories.
--time=word
Replace the output of the last modified time with the following words (Wrod): atime, Access, use, CTime or status

--time-style=style
Show times using style style:
Full-iso, Long-iso, ISO, +format
FORMAT is interpreted like ' date '

--HELP displays this help information and exits
--version output version information and exit
[Size] can be the following units (preceded by an integer):
KB 1000,k 1024,mb 1000000,m 1048576, and G, T, P, E, Z, Y

Explain help

About-0 (here is 0)

Look at the difference:
$du –a./

As shown in figure:

$du –a0./

Plus-0, the effect is as shown:

Instance:

1. $du-B du.txt

The file is too small and you can use-M, k, or even yourself to define the size

Effect as shown:

2. $du –ak dir | SORT–NRK 1 | Head

-a lists all k is in 1kb units, sort sorted, head print Top 10, dir is directory

As shown in figure:

Closure

Here is a simple explanation, if the direct copy of the command in the text, note that the symbol "-" is actually changed, need to modify.

This article comes from "Scholar" blog

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.