如何在Linux中查看文件和目录的大小?如果使用df -m,那么它会显示所有目录在顶层的大小,但是,对于目录内的目录和文件,我如何检查大小?
当前回答
我更喜欢这个命令ll -sha。
其他回答
文件大小(MB)
ls -l --b=M filename | cut -d " " -f5
文件大小(GB)
ls -l --b=G filename | cut -d " " -f5
这是du命令。
目录和/或文件的大小,以一种人性化的方式:
$ du -sh .bashrc /tmp
我把它当成一个不存在的英语单词来记忆。
——-size命令行开关使它测量表观大小(ls显示的),而不是实际的磁盘使用量。
我更喜欢这个命令ll -sha。
ls -sh video.mp4 | sed s/video.mp4//g
输出, 5.6米
文件使用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
推荐文章
- Linux Bash中双&和分号有什么区别?
- 在SSH会话中查找客户端的IP地址
- C++ Linux的想法?
- 如何为Fedora安装g++ ?
- 如何删除文件中的特定行?
- Linux删除大小为0的文件
- Spring引导应用程序作为服务
- 如何重定向标准derr和标准输出到不同的文件在同一行脚本?
- Windows和Linux上的c++编译:ifdef开关
- Linux: kill后台任务
- 使用Java重命名文件
- 如何修改Linux系统中打开文件的数量限制?
- 如何从Python包内读取(静态)文件?
- errno线程安全吗?
- 为什么我得到“Pickle - EOFError: run out of input”读取一个空文件?