View file and folder sizes under Linux

Source: Internet
Author: User
Tags disk usage

When the size of the disk exceeds the standard, there will be alarm prompts, if you know the DF and du command is a very wise choice.

DF can view the first-level folder size, usage scale, file system and its hang-in points, but there is nothing to file.
Du can view the size of files and folders.

It works well with both. For example, use DF to see which level of directory is too large, and then use DF to see the size of the folder or file, so you can quickly determine the crux of the problem.

The following is a brief introduction

The DF command can show the available space and usage for all current file systems , as shown in the following example:

here is the code snippet:

[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

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

The first field (Filesystem) and the last field (mounted on) of the above command output are the file system and its hang-in points respectively. We can see that this partition of/DEV/SDA1 is hung in the root directory.

The next four fields size, used, Avail, and use% are the partition's capacity, the size used, the remaining size, and the percentage used. Under FreeBSD, when the hard disk is full, you may see that the percentage used is more than 100%, because FreeBSD leaves some room for root, allowing Root to be managed when the file system is full, or can write something to the file system.

du: Querying disk usage space for a file or folder

If you have a lot of files and folders under the current directory, you can cycle through the space used by all files and folders using the command without the parameter Du. This is not good to see if it is too large, so you have to specify the number of layers in the depth directory, parameter:--max-depth=, this is a very useful parameter! As follows, note that using "*", you can get the space size of the file.

Reminder : Always command more complex than Linux FreeBSD, its du command specifies the depth of the directory layer is more simplified than Linux, the-D.

here is the code snippet:

[Email protected] yayu]# du-h--max-depth=1 work/testing
27M Work/testing/logs
35M work/testing

[Email protected] 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

[Email protected] yayu]# du-h--max-depth=1 work/testing/logs/
27M work/testing/logs/

[Email protected] 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

It's worth noting that you see an article on the similarities and differences between the Du and DF commands: the du DF difference causes file system false positives to resolve.

Du statistics File size addition
DF Statistics block usage

If a process opens a large file, the large file is dropped directly by RM or MV, then du updates the statistics, DF does not update the statistics, or the space is not released. Until the process of opening the large file was killed.

As a result, if you delete the file below/var/spool/clientmqueue periodically, the space is not released until you kill the process.

After you kill the process using the following command, the system resumes.
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 that the folder contains

Total statistics Size

Du-sh xmldb/

DU-SM * | Sort-n//Statistics current directory size and size sorting

Du-sk * | Sort-n

Du-sk * | grep GUOJF//Look at the size of a person

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

40752

Explain:

WC [-LMW]

Parameter description:

-L: How many lines

-M: How many characters

-W: how many words

View file and folder sizes under Linux

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.