Check file and folder size under Linux

When the disk size exceeds the standard, there will be an alarm prompt. At this time, it is a very wise choice to master the df and du commands.

    df can view the first-level folder size, usage ratio, file system and its mount point, but it can't do anything about the file.
    du can view the size of files and folders.

    Used together, the two are very effective. For example, use df to see which first-level directory is too large, and then use df to check the size of a folder or file, so that the crux can be quickly determined.

    A brief introduction to the following

    The df command can display the current free space and usage of all file systems , see 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 "Human-readable" output, that is, the use of readable formats such as GB and MB in the file system size.

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

    The next four fields Size, Used, Avail, and Use% are the capacity of the partition, the used size, the remaining size, and the percentage used. Under FreeBSD, when the hard disk capacity is full, you may see that the percentage used exceeds 100%, because FreeBSD will leave some space for root, so that root can still write things to the file system when the file system is full. to manage.

    du: Query the disk space of a file or folder

    If there are many files and folders in the current directory, use the command without parameter du to cyclically list the space used by all files and folders. This is not good for checking which place is too large, so you have to specify the number of layers deep into the directory, parameter: --max-depth=, this is a very useful parameter! As follows, pay attention to the use of "*", you can get the size of the used space of the file.

    Reminder : FreeBSD, which has always been more complicated than linux, its du command specifies the number of layers deep into the directory, but it is simpler than linux, which is -d.

 

 

Here is the code snippet:

[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和df命令异同的文章:《du df 差异导致文件系统误报解决》。

    du 统计文件大小相加 
    df  统计数据块使用情况

    如果有一个进程在打开一个大文件的时候,这个大文件直接被rm 或者mv掉,则du会更新统计数值,df不会更新统计数值,还是认为空间没有释放。直到这个打开大文件的进程被Kill掉。

    如此一来在定期删除 /var/spool/clientmqueue下面的文件时,如果没有杀掉其进程,那么空间一直没有释放。

    使用下面的命令杀掉进程之后,系统恢复。
    fuser -u /var/spool/clientmqueue

http://www.yayu.org/look.php?id=162

 


 

 

查看linux文件目录的大小和文件夹包含的文件数

    统计总数大小

    du -sh xmldb/

    du -sm * | sort -n //统计当前目录大小 并安大小 排序

    du -sk * | sort -n

    du -sk * | grep guojf //看一个人的大小

    du -m | cut -d "/" -f 2 //看第二个/ 字符前的文字

    查看此文件夹有多少文件 /*/*/* 有多少文件

    du xmldb/

    du xmldb/*/*/* |wc -l

    40752

    解释:

    wc [-lmw]

    参数说明:

    -l :多少行

    -m:多少字符

    -w:多少字

 

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


 

Linux:ls以K、M、G为单位查看文件大小

#man ls

……

-h, --human-readable

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

……

# ls

cuss.war    nohup.out

# ls -l

total 30372

-rw-r--r--    1 root root 31051909 May 24 10:07 cuss.war

-rw-------    1 root root          0 Mar 20 13:52 nohup.out

# ls -lh

total 30M

-rw-r--r--    1 root root 30M May 24 10:07 cuss.war

-rw-------    1 root root     0 Mar 20 13:52 nohup.out

# ll -h

total 30M

-rw-r--r--    1 root root 30M May 24 10:07 cuss.war

-rw-------    1 root root     0 Mar 20 13:52 nohup.out

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326314023&siteId=291194637