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 to view file sizes

2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

How to use the du command to check the file size, for this problem, this article describes in detail the corresponding analysis and answers, hoping to help more partners who want to solve this problem to find a more simple and easy way.

Du-ah-- max-depth=1 this is the result I want a to show all the files and folders in the directory (excluding subdirectories), h to show in a way that humans can understand, and max-depth to show the depth of the directory.

Du-sh directory # View the size of the directory

Du-sh file # View file size

The du command is used to view the amount of disk space occupied by a directory or file. The common combination of options is: du-sh

The function of du: `du` reports the amount of disk space used by the specified files and for each subdirectory (of directory arguments). With no arguments, `du` reports the disk space for the current directory.

Obviously, unlike df, it is used to see how much disk space a file or directory takes up.

Second, the options commonly used in du:

-h: display in a human-readable manner

-a: displays the amount of disk space occupied by the directory, as well as the amount of disk space occupied by directories and files under it

-s: displays the disk space occupied by the directory, not the disk space occupied by subdirectories and files under it

-c: displays the disk space occupied by several directories or files, as well as the sum of them

-- apparent-size: displays the size of the directory or file itself

-l: count the disk space occupied by hard links

-L: statistics on the amount of disk space occupied by files pointed to by symbolic links

1. Du-h: I won't say much about this.

Du-a: displays the amount of disk space occupied by the directory and subdirectories and files under the directory when using this option.

As you can see, by default, du shows only the amount of disk space occupied by the download directory, but with the-an option, it shows not only the directory (the last line), but also the amount of disk space occupied by individual files under the directory.

3. Du-s: when using this option, du displays only the amount of disk space occupied by the directory, and does not display information about the disk space occupied by subdirectories and files under it.

Du-c: when using this option, not only displays the size of disk space occupied by several files or directories, but also counts the sum of them.

Du-csh directory: with the-c option added, du not only displays the amount of disk space occupied by each of the two directories, but also sums them up on the last line.

6. Du-l: this option is mainly for hard links. When the statistical directory takes up disk space, the-l option counts hard links as well. The help documentation is interpreted as follows: Count the size of all files,even if they have appeared already (as a hard link).

We set up a hard link in the download directory to point to a file in this directory. When not using the-l option, du finds that the hard link points to the file in this directory, so it automatically ignores the linked file to avoid duplicate statistics; using the-l option, du will count the hard-linked file in.

7. Du-L: this option is mainly for symbolic links. It also counts the amount of disk space occupied by the files pointed to by symbolic links. The help documentation is interpreted as follows: Dereference symbolic links (show the disk space used by the file or directory that the link points to instead of the space used by the link).

We create a symbolic link in the download directory to point to a file in this directory. We see the results shown in the image above. When using the-L option, du will count the size of the file pointed to by the symbolic link to the directory.

This is the answer to the question about how to use the du command to view the file size. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.

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: 270

*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

Internet Technology

Wechat

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

12
Report