Code-Life
Code-Life copied to clipboard
linux command find
find 命令
基础版查询文件
find {path} -name "{filename}"
-type
- 查找的为文件形式
-type f - 查找的为目录形式
-type d
ctime
基础版
find . -name "*.txt" -ctime +/-{time}
数字前面的正负号的含义
+n for greater than n,
-n for less than n,
n for exactly n.
寻找前一天内的文件 后缀为".txt"
find . -name "*.txt" -type f -ctime -1
寻找30天以前的所有文件 后缀为".txt"
find . -name "*.txt" -type f -ctime +30
exec
表示执行命令
可以执行cp, mv, chmod等命令
将目录中的txt文件删除
find . -name "*.txt" -ctime -1 -exec rm -rf {} \;
记得要带上 \;