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 use the du command in linux

2025-03-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

In this issue, the editor will bring you about how to use the du command in linux. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

Du-sh * View the folder size under the current directory

Du command

Use

An overview of disk usage.

Grammar

Du [

-a

| |

S

] [

-k

] [

-m

] [

-g

] [

-l

] [

-r

] [

-x

] [

-H

| |

-L

] [File...]

Description

The du command in linux displays the number of blocks used for the file. If the specified File parameter is actually a directory, all files in that directory are reported. If no File parameter is provided, the du command in linux uses the files in the current directory.

If the File parameter is a directory, the number of blocks reported is the sum of the blocks allocated to the files in the directory and to the directory itself.

Designation

-a

Flag to report the number of blocks in the individual file. Individual files specified by the File parameter are always listed, regardless of whether or not the-a flag is used.

Designation

S

Flag that reports all blocks used for all files in the specified file and directory.

The block count includes indirect blocks for each file. The block count is calculated in 512-byte units, regardless of the cluster size used by the system. Designation

-k

Flag to calculate the number of blocks in 1024 byte units.

Note:

Files with multiple links count and write for only one item.

Because the block count is based only on file size, unallocated blocks are not included in the number of blocks reported.

If the du command in linux does not get the file attributes or cannot read the directory, it reports an error and affects the exit status of the command.

Mark

-a

Displays disk usage for each specified file, or individual disk usage for each file in the directory. Compare this logo with the-s flag.

-g

The number of blocks is calculated in GB units instead of the default 512-byte units. The output value for disk usage should be a floating-point number, because the value can be very large in bytes.

-H

If a symbolic link is specified on the command line, the du command in linux counts the size of the file or file hierarchy referenced by the link.

-k

The number of blocks is calculated in 1024 byte units instead of the default 512 byte units.

-l

Distribute blocks evenly between file links and multiple links. According to the default, files with two or more links are counted only once.

-L

If you specify symbolic links on the command line or encounter symbolic links multiple times during traversal of the file hierarchy, the du command in linux should count the size of the file or file hierarchy referenced by the link.

-m

The number of blocks is calculated in MB units instead of the default 512-byte units. The output value for disk usage should be a floating-point number, because the value can be very large in bytes.

-r

Report a file or directory name that is not accessible. This is the default setting.

S

Displays the entire disk usage for all specified files, or the overall disk usage for all files in a directory. Compare the logo with the-a flag.

-x

When evaluating file size, only those files that reside on the same device as the files or directories specified by the File parameter are evaluated. For example, you can specify a directory that contains files on multiple devices. In this case, the-x flag shows the block size for all files that reside on the same device as the directory.

If all the-k,-m, and-g flags are specified, or any two of them, the one specified by * works. Output disk usage with the flags-m and-g will approximate to the nearest second decimal number.

Exit statu

This command returns the following export values:

0

It ended successfully.

> 0

An error has occurred.

Example

To summarize the disk usage of a directory tree and each of its subtrees, enter:

Du / home/fran

This shows the number of disk blocks in the / home/fran directory and each of its subdirectories.

To summarize the disk usage of a directory tree and each of its subtrees with 1024-byte blocks, enter: du-k / home/fran, which shows the number of 1024-byte disk blocks in the / home/fran directory and each subdirectory.

To outline the disk usage of a directory tree and each of its subtrees through MB blocks, enter: du-m / home/fran, which shows the number of MB blocks (approximate to the nearest second decimal number) in the / home/fran directory and each subdirectory.

To outline the disk usage of a directory tree and each of its subtrees through GB blocks, enter: du-g / home/fran, which shows the number of GB disk blocks (approximate to the nearest second decimal number) in the / home/fran directory and each subdirectory.

To display the disk usage of each file, enter: du-a / home/fran, which shows the number of disk blocks contained in each file and subdirectories of the directory / home/fran. The number next to the directory is the disk usage of the directory tree. The number next to the regular file is the individual disk usage of the file.

To display all disk usage for only one directory tree, enter the du-s / home/fran-s flag to control the du command in linux, showing only the sum of the disk usage of the / home/fran directory and the files it contains. By default, if the du command in linux cannot read a file or directory, an error message is displayed.

In addition to the regular files found in the traversal of / home/fran, but also to show the disk usage of all symbolic links referenced files or file hierarchies, enter: du-L / home/fran

To report disk use of files or file hierarchies referenced by symbolic links mylink, enter: du-H mylink

File

/ usr/bin/du

Contains the du command in linux.

This is how the du command in linux shared by Xiaobian is used. If you happen to have similar doubts, please refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

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