View the file and folder size in Linux

Source: Internet
Author: User

When the disk size exceeds the standard, an alarm is triggered. it is wise to master the DF and Du commands.

DF allows you to view the size, usage ratio, file system, and its mount point of a level-1 folder, but there is nothing to do with files.
Du allows you to view the file and folder size.

They are very effective when used in combination. For example, you can use DF to check which level directory is too large, and then use DF to view the size of the folder or file, so that you can quickly determine the crux of the problem.

The following is a brief introduction.

The DF command displays the available space and usage of all file systems.See the following example:

 

Below isCodeFragment:

[Yayug @ Yayu ~] $ DF-H
Filesystem size used avail use % mounted on
/Dev/sda1 3.9g 300 m 3.4g 8%/
/Dev/sda7 100g 188 M 95g 1%/data0
/Dev/sdb1 133g 80g 47g 64%/data1
/Dev/sda6 7.8g 218 M 7.2g 3%/var
/Dev/sda5 7.8g 166 m 7.2g 3%/tmp
/Dev/sda3 9.7g 2.5 GB 6.8g 27%/usr
Tmpfs 2.0g 0 2.0g 0%/dev/SHM

 

The-h Parameter indicates that "human-readable" is used for output, that is, the file system uses readable formats such as GB and MB.

The first field output (filesystem) and the last field (mounted on) are respectively the File System and Its mount point. We can see that the/dev/sda1 partition is mounted under the root directory.

The following four fields: Size, used, avail, and use % are the capacity, used size, remaining size, and percentage of the shard. In FreeBSD, when the hard disk capacity is full, you may see that the percentage used exceeds 100%, because FreeBSD will leave some space for the root user to make the root user full in the file system, you can also write something to the file system for management.

Du: queries the disk space used by files or folders.

If there are many files and folders in the current directory, you can use the command without the du parameter to list the space used by all files and folders cyclically. This is not good for checking whether the location is too large. Therefore, you must specify the number of layers in the directory. The parameter is -- Max-depth =, which is a very useful parameter! As shown in the following figure. Use "*" to obtain the space used by the file.

Reminder: FreeBSD, which has always been a more complex command than Linux, uses the "du" command to specify the number of layers in the directory, which is simpler than that in Linux-D.

 

The following is a code snippet:

[Root @ bsso Yayu] # Du-h -- Max-depth = 1 work/Testing
27 m Work/testing/logs
35 m Work/Testing

[Root @ bsso Yayu] # Du-h -- Max-depth = 1 work/testing /*
8.0 K work/testing/func. php
27 m Work/testing/logs
8.1 m Work/testing/nohup. Out
8.0 K work/testing/testing_c.php
12 K work/testing/testing_func_reg.php
8.0 K work/testing/testing_get.php
8.0 K work/testing/testing_g.php
8.0 K work/testing/var. php

[Root @ bsso Yayu] # Du-h -- Max-depth = 1 work/testing/logs/
27 m Work/testing/logs/

[Root @ bsso Yayu] # Du-h -- Max-depth = 1 work/testing/logs /*
24 k work/testing/logs/errdate. log_show.log
8.0 K work/testing/logs/pertime_show.log
27 m Work/testing/logs/show. Log

 

It is worth noting that the similarities and differences between du and DF commands are shown.Article: Solutions to false positives caused by difference in Du DF.

Du statistics file size Addition
DF statistics block usage

If a process directly loses rm or mV when opening a large file, du updates the statistical value and DF does not update the statistical value, I still think the space is not released. Until the process of opening a large file is killed.

In this way, when files under/var/spool/clientmqueue are deleted regularly, if the process is not killed, the space is never released.

Use the following command to kill the process and the system recovers.
Fuser-U/var/spool/clientmqueue

Http://www.yayu.org/look.php? Id = 162

 

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 // 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 /*

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

 

Http://linux.chinaitlab.com/command/734706.html

Linux: ls displays the file size in the unit of K, M, and G.

# Man ls

......

-H, -- human-readable

Print sizes in human readable format (e.g., 1 K 234 M 2g)

......

# Ls

Cuss. War nohup. Out

# Ls-l

Total 30372

-RW-r -- 1 Root 31051909 May 24 10:07 cuss. War

-RW ------- 1 Root 0 Mar 20 13:52 nohup. Out

# Ls-lH

Total 30 m

-RW-r -- 1 Root 30 m May 24 :07 cuss. War

-RW ------- 1 Root 0 Mar 20 13:52 nohup. Out

# Ll-H

Total 30 m

-RW-r -- 1 Root 30 m May 24 :07 cuss. War

-RW ------- 1 Root 0 Mar 20 13:52 nohup. Out

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.