我的系统怎么了-系统信息查看(二)du统计文件大小,tree/ls查看目录结构和文件数量
经常有使用北京大学北极星高性能计算平台的同学问,磁盘没有配额了,除了磁盘空间问题还有文件数超了,那么我们除了用文件系统的磁盘配额目录外,还可以用du去统计文件数和文件所占空间。
一、使用tree查看目录结构,文件数;使用ls查看文件数
1、只查看目录
[test_pkuhpc@login12 2019test]$ tree -d cuda
cuda
├── old
├── test
└── test2
└── test2
2、查看第一层,第二层,第N层目录
第一层
[test_pkuhpc@login12 2019test]$ tree -L 1 cuda
cuda
├── a.out
├── getgpudeviceCount
├── getgpudeviceCount.cu
├── getgpuinfo
├── getgpuinfo.cu
第二层
[test_pkuhpc@login12 2019test]$ tree -L 2 cuda
cuda
├── a.out
├── getgpudeviceCount
├── old
│ ├── getgpudeviceCount
│ ├── getgpudeviceCount.cu
├── test2
│ ├── test2
│ ├── tgp090546_992047.err
│ ├── tgp090546_992047.out
第三层:
第N层目录:
[test_pkuhpc@login12 2019test]$ tree -a cuda/
cuda/
├── a.out
├── getgpudeviceCount
├── getgpudeviceCount.cu
├── getgpuinfo
├── getgpuinfo.cu
├── nvi193303_866896.err
├── nvi193303_866896.out
├── old
│?? ├── getgpudeviceCount
│?? ├── getgpudeviceCoun
3、查看文件数 tree统计
[test_pkuhpc@login12 2019test]$ tree -a
4、使用ls结合其他命令统计:
[test_pkuhpc@login12 2019test]$ tree -a cuda
├── tgpuadd.cu
└── tgpu.cu
4 directories, 82 files ##82个文件
[test_pkuhpc@login12 2019test]$ ls -l cuda/ | grep "^-" | wc -l ## 一级目录下所有文件,其中grep "^-"为文件(见下图)
39
[test_pkuhpc@login12 2019test]$ ls -lR cuda/ | grep "^-" | wc -l ##cuda目录下的所有文件,包括子目录 ,其中-R为遍历目录
82
[test_pkuhpc@login12 2019test]$ ls -lR cuda/ | grep "^d" | wc -l ##cuda目录下的所有目录,包括子目录 ,其中-R为遍历目录
4
第一列定义文件类型,红色圈为文件,蓝色圈为文件夹
二、使用du查看占用空间
du -h 输出文件系统分区使用的情况,例如:10KB,10MB,10GB等
-s 显示文件或整个目录的大小,默认单位是KB
查找占用空间最大的文件与目录:du -h --max-depth=1
显示当前目录的大小:
写法的区别:
du -sh xxx 显示总目录的大小,但是不会列出目录中的每一个文件
du -sh xxx/* 列出xxx下每个目录和文件所占的容量
[test_pkuhpc@login12 2019test]$ du -h cuda
3.5Mcuda/old
1.2Mcuda/test2/test2
3.0Mcuda/test2
1.3Mcuda/test
13Mcuda
[test_pkuhpc@login12 2019test]$ du -sh cuda
13Mcuda
以下会列出所有文件
[test_pkuhpc@login12 2019test]$ du -sh cuda/*
632Kcuda/a.out
584Kcuda/getgpudeviceCount
4.0Kcuda/getgpudeviceCount.cu
628Kcuda/getgpuinfo
4.0Kcuda/getgpuinfo.cu
0cuda/nvi193303_866896.err
4.0Kcuda/nvi193303_866896.out
3.5Mcuda/old
4.0Kcuda/tcp090645_992048.err
0cuda/tcp090645_992048.out
0cuda/tcp090651_992049.err
4.0Kcuda/tcp090651_992049.out
三、使用du排除文件夹来统计
du -sh /* --exclude="proc" 或使用
模糊匹配 du -sh /* --exclude="*proc*"
如:
[test_pkuhpc@login12 cuda]$ du -h --exclude="test"
[test_pkuhpc@login12 cuda]$ du -h --exclude="test*"##模糊匹配
[test_pkuhpc@login12 cuda]$ du -h --exclude="test*" --exclude="old" ##多个目录