Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to check the size of files and folders under Linux

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to check the size of files and folders under Linux". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to check file and folder size under Linux.

Df can view the first-level folder size, usage ratio, file system and its mount point, but there is nothing you can do with files.

Du can view the size of files and folders.

The combination of the two is very effective. For example, use df to see which first-level directory is too large, and then use df to check the size of folders or files, so you can quickly determine the crux of the problem.

The following is a brief introduction

The df command displays the free space and use cases of all current file systems. Take a look at the following example:

The code is as follows:

[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 per cent / tmp

/ dev/sda3 9.7G 2.5G 6.8G 27% / usr

Tmpfs 2.0G 0 2.0G 0% / dev/shm

The parameter-h indicates that the output of "Human-readable" is used, that is, easy-to-read formats such as GB, MB, etc. are used 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 partition / dev/sda1 is hung 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, respectively. Under FreeBSD, when the hard disk capacity is full, you may see that the percentage used is more than 100%, because FreeBSD will leave some space for root, so that root can still write to the file system for management when the file system is full.

Du: query disk usage space for files or folders

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

Reminder: for FreeBSD, which has always been more complex than linux, its du command specifies the number of layers in the deep directory is simpler than linux, which is-d.

The code is as follows:

[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

Add the size of du statistics file

Df statistics block usage

If a process opens a large file and the large file is dropped directly by rm or mv, du will update the statistics, df will not update the statistics, or the space will not be freed. Until the process of opening large files is dropped by Kill.

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

After killing the process with the following command, the system recovers.

Fuser-u / var/spool/clientmqueue

At this point, I believe you have a deeper understanding of "how to view file and folder size under Linux". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report