Code-Life icon indicating copy to clipboard operation
Code-Life copied to clipboard

linux command find

Open Draymonders opened this issue 5 years ago • 3 comments

find 命令

基础版查询文件 find {path} -name "{filename}"

Draymonders avatar May 09 '20 03:05 Draymonders

-type

  • 查找的为文件形式 -type f
  • 查找的为目录形式 -type d

Draymonders avatar May 09 '20 03:05 Draymonders

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

Draymonders avatar May 09 '20 03:05 Draymonders

exec

表示执行命令 可以执行cp, mv, chmod等命令

将目录中的txt文件删除

find . -name "*.txt" -ctime -1 -exec rm -rf {} \; 记得要带上 \;

Draymonders avatar May 09 '20 03:05 Draymonders