linux命令获取特定文件夹中存在的文件和目录的大小?

新手上路,请多包涵

如何在 Linux 中查看文件和目录的大小?如果使用 df -m ,那么它会在顶层显示所有目录的大小,但是对于目录内的目录和文件,我如何检查大小?

原文由 Advait 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 559
2 个回答

对文件使用 ls du ,对目录使用 --- 命令。

检查文件大小

ls -l filename   #Displays Size of the specified file
ls -l *          #Displays Size of All the files in the current directory
ls -al *         #Displays Size of All the files including hidden files in the current directory
ls -al dir/      #Displays Size of All the files including hidden files in the 'dir' directory

ls 命令不会列出目录的实际大小( 为什么? )。因此,我们为此使用 du

检查目录大小

du -sh directory_name    #Gives you the summarized(-s) size of the directory in human readable(-h) format
du -bsh *                #Gives you the apparent(-b) summarized(-s) size of all the files and directories in the current directory in human readable(-h) format

Including -h option in any of the above commands (for Ex: ls -lh * or du -sh ) will give you size in human readable format ( kb , mb , gb , …)

有关详细信息,请参阅 man lsman du

原文由 Sandeep 发布,翻译遵循 CC BY-SA 4.0 许可协议

du 命令。

目录和/或文件的大小,以人性化的方式:

 $ du -sh .bashrc /tmp

我把它记为一个不存在的英文单词 dush


--apparent-size 命令行开关使其测量表面大小( ls 显示)而不是实际磁盘使用情况。

原文由 Maxim Egorushkin 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题