Linux Find
2013-04-26 22:45 三犬风 阅读(672) 评论(0) 编辑 收藏 举报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