Command for viewing file and folder size in Linux

Source: Internet
Author: User

To view the file size in linux, run the df command. To view the folder size, run the du command. For more information, see. ,


The df command can display the available space and usage of all file systems. See the following example:

The following is a code snippet:

The Code is as follows: Copy code
[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 Df command is used to view the file system by disk partition in linux. You can add parameters to view the remaining disk space. The command format is as follows:

The Code is as follows: Copy code
Df-hl

Display format:
File System capacity used available % mount point

The Code is as follows: Copy code
Filesystem Size Used Avail Use % Mounted on
/Dev/hda2 45G 19G 24G 44%/
/Dev/hda1 494 M 19 M 450 M 4%/boot
/Dev/hda6 4.9G 2.2G 2.5G 47%/home
/Dev/hda5 9.7G 2.9G 6.4G 31%/opt
None 1009 M 0 1009 M 0%/dev/shm
/Dev/hda3 9.7G 7.2G 2.1G 78%/usr/local
/Dev/hdb2 75G 75G 0 100%/
/Dev/hdb2 75G 75G 0 100%/

The preceding output is used as an example to indicate:

HD hard disk interface second hard disk (B), second partition (2), capacity is 75G, 75G used, available is 0, so the utilization is 100%, mounted to the root partition directory (/).

The following is an explanation of the relevant commands:

Df-hl view the remaining disk space

Df-h: view the partition size of each root path

Du-sh [directory name] returns the directory size

Du-sm [Folder] returns the total number of MB in this folder.

For more functions, run the following command:

Df -- help

Du -- help


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 is always more complex than linux, uses the "du" command to specify the number of layers in the directory, which is simpler than that in linux. It is-d.


The following is a code snippet:

The Code is as follows: Copy code

[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

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.