1. Find old files and delete

-exec: find命令对匹配的文件执行该参数所给出的shell命令。相应命令的形式为'command' { } \;,注意{ }和\;之间的空格。

-mtime   -n +n                #按文件更改时间来查找文件,-n指n天以内,+n指n天以前

-ctime    -n +n              #按文件创建时间来查找文件,-n指n天以内,+n指n天以前

-type    b/d/c/p/l/f         #查是块设备、目录、字符设备、管道、符号链接、普通文件

"find $HOME -type f -mtime +365 -exec ls -lh {} +" will give you the size and path of every file over 365 days old in your home directory

2. Find big files and delete

-size      n[c]               #查长度为n块[或n字节]的文件

"find $HOME -type f -size +2G -exec ls -lh {} +" will give you the size and path of every file over 2 GB in your home directory

3. Combine 1 & 2

"find $HOME -type f -size +2G -mtime +365 -exec ls -lh {} +"

4. delete specific files under $HOME

find $HOME -name 'test-file-*' | xargs rm -rf (use rm directly would fail if the file number is more than 20,000)

-iname will case-insensitive

相关文章:

  • 2021-11-29
  • 2021-06-03
  • 2021-05-24
  • 2021-06-08
  • 2021-08-18
猜你喜欢
  • 2021-10-23
  • 2021-10-07
  • 2022-01-11
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案