The right-click attribute is inconsistent with the file size displayed by du-sh.

Source: Internet
Author: User

The right-click attribute is inconsistent with the file size displayed by du-sh.

Du-sh filename (in fact, we often use du-sh * to display all the files in the current directory and their sizes. If you want to sort them, add | sort-n)

The solution to the inconsistency between the Right-click attribute and the file size displayed by du-sh: in short, I understand that du finds the block size on the actual hard disk, including many hidden files, soft, hard links, as well as disk format Division issues, lead to inconsistency, right-click attribute is equivalent Du -- exclude = '. *' -- exclude = '*~ '-B-D-s your files or folders and other unnecessary things. Du-sh is all displayed, so it is large.(I think it is reasonable for Baidu) There are several problems, which lead to several file size calculation methods.

1. Content size and disk (or other storage devices) usage, such
# The file content is a line break with three letters

~ /Tmp $ cat abc.txt
Efg


# The content size is 4 bytes (-- apparent-size calculates the content size, -- block-size = 1 in bytes)
~ /Tmp $ du -- apparent-size -- block-size = 1 abc.txt
4 abc.txt


# Occupies 4096 bytes of disk space. This result is closely related to the disk format.
~ /Tmp $ du -- block-size = 1 abc.txt
4096 abc.txt

2. symbolic links or soft links or symlinks
# Here is a symbolic link pointing to the file just now.

~ /Tmp $ ls-nl link_abc.txt
Lrwxrwxrwx 1 1000 1000 7 Jan 28 link_abc.txt-> abc.txt


# Symbolic links do not occupy "ordinary" disk space, just like an empty file.
~ /Tmp $ du -- block-size = 1 link_abc.txt
0 link_abc.txt


# However, the content size still exists. It is actually "abc.txt" with a total of 7 characters.
~ /Tmp $ du -- apparent-size -- block-size = 1 link_abc.txt
7 link_abc.txt
~ /Tmp $


# In addition, you should check the size of the file to be pointed to (same as in the beginning)
~ /Tmp $ du -- apparent-size -- block-size = 1-L link_abc.txt
4 link_abc.txt


3. File hiding
A file or Tilde starting "~ "The ending object is a hidden object.

~ /Tmp $ ls
Abc.txt link_abc.txt

~ /Tmp $ ls-
Abc.txt link_abc.txt. xxx

(But it seems that for the ls command "*~ "Not a hidden file)

  4. space occupied by folders
# Du is the size of the folder.

~ /Tmp $ du -- exclude = '. *' -- exclude = '*~ '-- Apparent-size-s-B-D ~ /Tmp
4107/home/xyy/tmp
# System File Management not counted (right-click attribute) The default Gnome File Manager nautilus ignores the hidden file when collecting the file size (corresponding to du -- exclude = '. *' -- exclude = '*~ '), It will be connected with a symbolic link (corresponding to du-D) to display the file content size (rather than disk usage), and carry it in December 1000 (du-B ).

The final combination is
Du -- exclude = '. *' -- exclude = '*~ '-B-D-s your file or folder

This article permanently updates the link address:

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.