如何在Linux中查看文件和目录的大小?如果使用df -m,那么它会显示所有目录在顶层的大小,但是,对于目录内的目录和文件,我如何检查大小?
当前回答
这是du命令。
目录和/或文件的大小,以一种人性化的方式:
$ du -sh .bashrc /tmp
我把它当成一个不存在的英语单词来记忆。
——-size命令行开关使它测量表观大小(ls显示的),而不是实际的磁盘使用量。
其他回答
您可以在这里使用ncdu磁盘使用分析器。它在ncurses接口中显示文件和目录的大小。您可以导航到每个目录,并从同一界面查看文件大小。
安装
$ sudo apt-get install ncdu
分析
$ ncdu <directory>
我更喜欢这个命令ll -sha。
你可以使用:
ls lh
使用此命令,您将看到目录的表观空间和文件的真实空间,以及所显示文件的详细名称,以及每个文件的大小和创建日期。
这是du命令。
目录和/或文件的大小,以一种人性化的方式:
$ du -sh .bashrc /tmp
我把它当成一个不存在的英语单词来记忆。
——-size命令行开关使它测量表观大小(ls显示的),而不是实际的磁盘使用量。
文件使用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
在上述任何命令中包含-h选项(例如:ls -lh *或du -sh)将以人类可读的格式给出大小(kb, mb,gb,…)
有关更多信息,请参阅man ls和man du
推荐文章
- 在Bash中检查变量是否存在于列表中
- 查看PS命令的全部输出
- 如何在Python中获得所有直接子目录
- 即使模板文件存在,Flask也会引发TemplateNotFound错误
- 如何在Ruby中创建文件
- Linux命令将域名转换为IP
- 如何从命令行在windows中找到mysql数据目录
- __FILE__宏显示完整路径
- 有效地测试Linux上的端口是否打开?
- 如何从另一个文件A中删除文件B中出现的行?
- 对以制表符分隔的文件进行排序
- 使用sudo时未找到命令
- 当有命令行参数时,如何使用GDB分析程序的核心转储文件?
- 如何强制从另一个SSH会话分离屏幕?
- 如何将文件指针(file * fp)转换为文件描述符(int fd)?