zoukankan      html  css  js  c++  java
  • Linux Find

    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

    Always go with the choice that scares you the most, because that's the one that is going to require the most from you!
  • 相关阅读:
    封装Socket.BeginReceive/EndReceive以支持Timeout
    使用反射动态创建类型实例
    泛型List<T>排序(利用反射)
    复旦版最佳医院排行 沪21家医院入选全国百佳
    C#格式化字符串
    一些很酷的.Net技巧
    系列文章--SQLite文章
    C#垃圾回收机制
    C#中Cache的使用
    ASP.NET Cache缓存的使用
  • 原文地址:https://www.cnblogs.com/sanquanfeng/p/3046010.html
Copyright © 2011-2022 走看看