1. find 命令
find(选项)(参数)
# 大于100M的文件
find /opt/ -type f -size +100M
---------------------------find 其他命令扩展-----------------------------------------------
# 当前目录搜索所有文件,文件内容 包含 “140.206.111.111” 的内容
find . -type f -name "*" | xargs grep "140.206.111.111"
#在/home目录下查找以.txt结尾的文件名
find /home -name "*.txt"
#基于正则表达式匹配文件路径
find . -regex ".*\(\.txt\|\.pdf\)$"
#同上,但忽略大小写
find . -iregex ".*\(\.txt\|\.pdf\)$"
# 借助-exec选项与其他命令结合使用
# 找出当前目录下所有root的文件,并把所有权更改为用户tom
find .-type f -user root -exec chown tom {} \;
#删除当前目录下所有.txt文件
find . -type f -name "*.txt" -delete
2.du 命令
显示每个文件和目录的磁盘使用空间,但是与df命令不同的是Linux du命令是对文件和目录磁盘使用的空间的查看
du [选项][文件]
# /opt 目录下所有文件占用空间大小, max-depth 表示深度为1,sort为排序,有个问题,1.2G会排到100M之前
du /opt/ -h --max-depth=1 | sort -n