How to view disk space in linux

Source: Internet
Author: User

How to view disk space in linux example to view the current directory size: Java code [root@typengine.com] # du-sh/var/www to view the specified directory size: java code [root@typengine.com] # du-sh/www/typengine.com view the total number of files in the current directory: Java code [root@typengine.com] # find. -type f | wc-l view the total number of files in the specified directory: Java code [root@typengine.com] # find/var/www-type f | wc-l view the total number of directories in the current directory: java codes [root@typengine.com] # find. -type d | wc-l view the total number of directories in the specified directory: Java code [root@typengine.com] # find/www/typengine-typ E d | wc-l: java code # du-ks --- in all # du-k --- every last du and df commands are used to obtain the linux system size information: df is used to report the total number of blocks and the remaining number of blocks in the file system, and du-s is used to report the number of blocks used by the file system. However, we can find that the number of blocks used by the file system calculated from the df command is inconsistent with the value obtained through the du command. For example: # du-s/tmp: --- 12920/tmp and df/tmp: java code Filesystem -- 512-blocks -- Free -- % Used -- Iused -- % Iused -- Mounted on/dev/hd3 -------- 57344 -- 42208 --- 26% ---- 391 ------ 4% --/tmp from the above value we can calculate-=: 57344-42208 = 15136. while 15136 is greater than 12920. The difference exists because the implementation of the du and df commands is different: the du-s command accumulates the total number of directories, symbolic links, and blocks used by the specified file system; the df command displays the block distribution chart of the file system to obtain the total number of blocks and the remaining number. The file system allocates some disk blocks to record some of its own data, such as I nodes, disk distribution charts, indirect blocks, and super blocks. This Data is invisible to most user-level programs, usually referred to as Meta Data. The du command is a user-level program that does not consider Meta Data, while the df command checks the disk distribution diagram of the file system and considers Meta Data. Df command to obtain the real file system data, while du command to view only part of the file system. For example, the distribution of Meta Data in a log file system with an empty frag = 4096 and nbpi = 4096 size of 4 MB is as follows: java code 1 4 k block for the LVM 2 4 k super blocks 2 4 k blocks for disk maps 2 4 k blocks for inode maps 2 4 k blocks. indirect 32 4 k blocks for inodes ----------------------- 41 4 k blocks for meta data on an empty 4 MB file system for AIX 4. version X: The result returned by executing du/foo is as follows: Java code ---- 8 -------/foo/lost + found ---- 16 ------/foo. The output result of the du command must be the same as that of the df command output. If matched, we must add Meta Data. First, convert 41 4 K blocks to a value in 512 bytes: Java code 41*8 = 328 328 (meta data) + 16 (from du) = 344 so 344 blocks in 512 bytes are allocated to this empty file system. Using the df/foo command, we can get the following results: java code Filesystem -- 512-blocks -- Free -- % Used -- Iused --- % Iused -- Mounted on/dev/lv01 ------ 8192 ----- 7848 ----- 5% ----- 16 ----- 2% ----/foo from which we can obtain the number of blocks used by the file system: java code 8192 (total blocks)-7848 (free blocks) = 344. This value is consistent with the above value. The above conversion method is easy to implement for an empty file system, but for a non-empty file system, it is difficult to implement because the indirect file block size in Meta Data is not fixed. You do not need to check the matching relationship between the values returned by du and df. Instead, you only need to know that the values returned by the du-s command reflect the number of disk blocks allocated to files and directories, the df command reflects the actual distribution of the file system. The df command reflects user Data (Files And Directories) and Meta Data. Another example showing the difference between the du command and the df command is as follows: if the user deletes a file in a directory opened by a running application, the value returned by the du command shows the directory size after the file is subtracted. However, the df command does not display the size after the file is subtracted. Until the running application closes the opened file, the value returned by df shows the usage of the file system after the file is subtracted. List the space occupied by a directory. 1. du, du-s, or du-k du-S | sort-n can quickly find that directory is the largest. 2. Use df to view the space and remaining space of the installed file system. 3. quota-v: view the user's disk space information. If you use quota to limit the user space size. Java code boot 5746310/boot [blinux @ localhost test] $ du-ks/boot 5772/boot [blinux @ localhost test] $ du-ms/boot 6/boot 3. displays the total directory size and the size of each folder in the directory tree, in a good unit, the Java code [blinux @ localhost test] $ du-h/boot 308 K/boot/grub 5.7 M/boot

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.