如何查看linux根分区下所有目录及文件的大小
答案:2 悬赏:0 手机版
解决时间 2021-03-07 22:56
- 提问者网友:战皆罪
- 2021-03-07 00:24
如何查看linux根分区下所有目录及文件的大小
最佳答案
- 五星知识达人网友:夜余生
- 2021-03-07 01:47
[root@minimal boot]# pwd/boot[root@minimal boot]# ls / |xargs du -shdu: cannot access `bin': No such file or directorydu: cannot access `boot': No such file or directorydu: cannot access `cgroup': No such file or directorydu: cannot access `dev': No such file or directorydu: cannot access `etc': No such file or directorydu: cannot access `home': No such file or directorydu: cannot access `lib': No such file or directory13K lost+founddu: cannot access `media': No such file or directorydu: cannot access `mnt': No such file or directorydu: cannot access `opt': No such file or directorydu: cannot access `proc': No such file or directorydu: cannot access `root': No such file or directorydu: cannot access `sbin': No such file or directorydu: cannot access `selinux': No such file or directorydu: cannot access `srv': No such file or directorydu: cannot access `sys': No such file or directorydu: cannot access `tmp': No such file or directorydu: cannot access `usr': No such file or directorydu: cannot access `var': No such file or directory[root@minimal boot]# cd /[root@minimal /]# ls |xargs du -sh5.9M bin28M boot4.0K cgroup480K dev31M etc20K home100M lib16K lost+found102M media64M mnt2.8G optdu: cannot access `proc/2533/task/2533/fd/4': No such file or directorydu: cannot access `proc/2533/task/2533/fdinfo/4': No such file or directorydu: cannot access `proc/2533/fd/4': No such file or directorydu: cannot access `proc/2533/fdinfo/4': No such file or directory0 proc139M root9.2M sbin0 selinux4.0K srv0 sys380K tmp2.6G usr116M varls与xargs配合使用时,ls只能显示当前的目录,所以要想显示根目录下的文件的大小,必须在根目录下配合使用ls与xargs命令 [root@minimal /]# ls |grep -v proc |xargs du -sh |sort -h0 selinux0 sys4.0K cgroup4.0K srv16K lost+found20K home380K tmp492K dev5.9M bin9.2M sbin28M boot31M etc64M mnt100M lib102M media116M var152M root2.6G usr2.8G opt按大小和单一模式显示除proc目录以外的所有根目录下的文件 /proc 这个目录本身是一个『虚拟档案系统』!它放置的数据都是在内存当中, 例如系统核心、形成信息、接口设备的状态及网络状态等等。因为这个目录下的数据都是在内存当中, 所以本身不占任何硬盘空间! [root@RedHat /]# ls -A |grep -v proc |xargs du -sh |sort -h0 .autofsck0 misc0 net0 selinux0 sys4.0K cgroup4.0K media4.0K srv12K .dbus16K lost+found28K mnt28K tmp712K dev7.3M root7.4M bin13M sbin19M boot33M etc102M lib177M var323M home2.9G opt3.6G usrls -A显示所有文件但不包括"."和"..";即当前目录和当前目录的父目录。[root@RedHat /]# ls -a |grep -v proc |xargs du -sh |sort -hdu: cannot access `./proc/9394/task/9394/fd/4': No such file or directorydu: cannot access `./proc/9394/task/9394/fdinfo/4': No such file or directorydu: cannot access `./proc/9394/fd/4': No such file or directorydu: cannot access `./proc/9394/fdinfo/4': No such file or directorydu: cannot access `../proc/9394/task/9394/fd/4': No such file or directorydu: cannot access `../proc/9394/task/9394/fdinfo/4': No such file or directorydu: cannot access `../proc/9394/fd/4': No such file or directorydu: cannot access `../proc/9394/fdinfo/4': No such file or directory0 .autofsck0 misc0 net0 selinux0 sys4.0K cgroup4.0K media4.0K srv12K .dbus16K lost+found28K mnt28K tmp712K dev7.3M root7.4M bin13M sbin19M boot33M etc102M lib177M var323M home2.9G opt3.6G usr7.1G .7.1G .. |grep -v proc 不显示proc目录du -sh 以单一模式显示文件或目录的大小|sort -h 按从小到大的顺序显示文件列表 注:通过上例发现管道太牛逼了,有空要好好研究一下。
全部回答
- 1楼网友:爱难随人意
- 2021-03-07 02:44
du命令用于查看磁盘的使用量,格式为:“ du [选项] [文件]”。
查看根目录中各文件夹所占空间:du -sh /
查看当前目录下各文件所占空间:du -sh *
编辑
参数 作用
-a 评估每个文件而非目录整体占用量。
-c 评估每个文件并计算出总占用量总和。
-h 更易读的容量格式如1k,234m,2g…
-s 仅显示占用量总和。
搜索《linux就该这么学》,第6章 存储结构与磁盘划分参考下!
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯