How to view file and folder sizes in Linux

Source: Internet
Author: User
Tags readable disk usage

For example, check the size of the home directory:

Du-s/home

You can also:

Du-sh/home

/usr/local/apache/bin/htcacheclean-v-p/cacheroot-l500m

Statistics:

Size Limit 500.0M

Total size is 91.8M, total size now 91.8M

Total entries is 3754, total entries now 3754

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.

Cases:
To summarize 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

When the disk size exceeds the standard there will be alarm prompts, then if Master df and du command is very wise choice.

DF can view the level of folder size, usage ratio, file system, and its mount points, but it does nothing for the file.
Du can view the size of files and folders.

They work together and are very effective. For example, use DF to see which level of directory is too large, and then use DF to view the size of folders or files, so you can quickly determine the crux.

The following is a brief introduction to each
The DF command can show the available space and usage for all current file systems, and see the following example:
The following is a code fragment:

[Yayug@yayu ~]$ Df-h
FileSystem Size Used Avail use% mounted on
/DEV/SDA1 3.9G 300M 3.4G 8%/
/dev/sda7 100G 188M 95G 1%/data0
/DEV/SDB1 133G 80G 47G 64%/data1
/dev/sda6 7.8G 218M 7.2G 3%/var
/dev/sda5 7.8G 166M 7.2G 3%/tmp
/dev/sda3 9.7G 2.5G 6.8G 27%/usr
Tmpfs 2.0G 0 2.0G 0%/dev/shm

Parameter-H indicates the use of "human-readable" output, that is, in the file system size using GB, MB, and other readable format.

The first field (filesystem) and the last field (mounted on) of the command output above are the file system and its mount point respectively. We can see/dev/sda1 this partition is hanging in the root directory.

The next four fields size, Used, avail, and use% are the capacity of the partition, the size used, the remaining size, and the percentage used. FreeBSD, when the hard drive is full, you may see that the percentage used is over 100%, because FreeBSD will leave some room for root, so that root can be written to the file system when the file system is full, for management.

Du: Querying for file or folder disk use space
View the current directory folder size

Du-sh

-S show Totals only
-H to the K, M, g units, improve the readability of information. KB, MB, GB is the conversion unit in 1024,-H to 1000 as the conversion unit

View the size of all subdirectories under the current directory. And sort from big to small

du-h | Sort-nr | More

[Root@localhost default]# du-h | Sort-nr | More
19M.

[root@localhost default]# DU-SM * | Sort-nr
Ten Discuz_x2.5_sc_gbk.zip
Ten Cmseasy_5.1_utf-8_20120708.zip
1 index.html

Du-sh * | Sort-nr

[root@localhost default]# Du-sh * | Sort-nr
9.7M Cmseasy_5.1_utf-8_20120708.zip
9.2M Discuz_x2.5_sc_gbk.zip
4.0K index.html

Explain:

Du
-S displays only the sum
-M displays in MB

Sort
-N Sort by number
-R Reverse Ordering

If you have a large number of files and folders in the current directory, you can iterate through the space used by all files and folders by using commands with no parameters du. This is a bad place to see if it's too big, so specify the number of layers in the Drill-down directory, Parameters: –max-depth=, which is a very useful parameter! For example, note that you can use "*" to get the size of the file space.

Reminder: It has always been ordered to be more complex than Linux, and its du command specifies that the number of layers in the Drill-down directory is simpler than Linux, FreeBSD.

The following is a code fragment:

[Root@bsso yayu]# du-h--max-depth=1 work/testing
27M Work/testing/logs
35M work/testing


[Root@bsso yayu]# du-h--max-depth=1 work/testing/*
8.0K work/testing/func.php
27M Work/testing/logs
8.1M Work/testing/nohup.out
8.0K work/testing/testing_c.php
12K work/testing/testing_func_reg.php
8.0K work/testing/testing_get.php
8.0K work/testing/testing_g.php
8.0K work/testing/var.php

[Root@bsso yayu]# du-h--max-depth=1 work/testing/logs/
27M work/testing/logs/

[Root@bsso yayu]# du-h--max-depth=1 work/testing/logs/*
24K Work/testing/logs/errdate.log_show.log
8.0K Work/testing/logs/pertime_show.log
27M Work/testing/logs/show.log

Du statistics File size added
DF Statistic block Usage

If there is a process opening a large file, the large file is directly out of RM or MV, then du will update the statistics, DF will not update the statistics, or think the space is not released. Until the process of opening a large file is killed.

This way, when the files below/var/spool/clientmqueue are deleted regularly, the space is not released unless the process is killed.

The system recovers after the process is killed using the following command.
Fuser-u/var/spool/clientmqueue

View the size of the Linux file directory and the number of files contained in the folder

Total statistics Size
Du-sh xmldb/
DU-SM * | Sort-n//Statistics current directory size and size sort
Du-sk * | Sort-n
Du-sk * | grep GUOJF//Look at the size of a person
du-m | Cut-d "/"-F 2//Look at the text before the second/character

See how many files there are in this folder/*/*/* how many files
Du xmldb/
Du xmldb/*/*/* |wc-l
40752

Explain:
WC [-LMW]

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

Linux:ls view file size in K, M, G

# ls
Cuss.war Nohup.out

# ls-l
Total 30372
-rw-r--r--1 root root 31051909 may 10:07 Cuss.war
-RW-------1 root 0 Mar 13:52 nohup.out

# LS-LH
Total 30M
-rw-r--r--1 root 30M May 10:07 Cuss.war
-RW-------1 root 0 Mar 13:52 nohup.out

# ll-h
Total 30M
-rw-r--r--1 root 30M May 10:07 Cuss.war
-RW-------1 root 0 Mar 13:52 nohup.out

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.