简体   繁体   English

使用python,终端命令(ubuntu)和文件夹属性的不同大小的文件夹

[英]Different size folders using python, terminal commands (ubuntu) and folder properties

I want to get the size of a folder I'm working on and I've tried the following: 我想获取正在处理的文件夹的大小,并且尝试了以下操作:

  • right-click and check folder's properties (105.8MB) 右键单击并检查文件夹的属性(105.8MB)

  • Commands directly in terminal: 直接在终端中的命令:

    • du -hsc * (last line where total appears 105MB) du -hsc *(总行显示105MB的最后一行)
    • du -sch (last line where total appears 418MB) du -sch(总行显示418MB的最后一行)
  • method from this answer: Calculating a directory size using Python? 这个答案的方法: 使用Python计算目录大小? (418MB) (418MB)

Why am I getting such different sizes? 为什么我会得到如此不同的尺寸?

du -sch * will ignore hidden directories, so you'll usually get a smaller size with the asterisk than just running du -sch . du -sch *将忽略隐藏的目录,因此与仅运行du -sch相比,使用星号通常会更小。 That's really the only difference between all your examples above. 这实际上是上述所有示例之间的唯一区别。

If you just need this value for displaying to a user, then choose which of those you'd like to display. 如果您只需要此值即可显示给用户,则选择要显示的值。

If you need an exact size, the du command is probably not what you want, since it displays disk usage , which will be different than file size if the disk block is greater than 1 byte. 如果您需要精确的大小,则du命令可能不是您想要的,因为它显示磁盘使用情况 ,如果磁盘块大于1个字节,它将与文件大小不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM