find是根据文件属性进行查找

属性有哪一些:

  • 文件大小
  • 文件3个时间,create_time(ctime),modify time (mtime),access time(atime)
  • 文件的inode节点
  • 文件的编码,权限

语法

find 路径 options option -paramter, option-parameter option paramter

-type :根据文件类型查找
** f: 普通文件 **
** d: 目录 **
l: link,快捷方式
s: socker
p:pid
c:character

-size:
+10K 大于10k
+10M 大于10M
-1G : 小于1G

-delete:直接删除
!: 不符合

-mmin
-amin
-cmin 分钟,
-10 10分钟之内
+10 10分钟之前

-mtime:
-atime:
-ctime: 天数
+10,10天之前
-10,10天之内

没有小时。

-samefile:查找相同的文件
–max-depth 2 深度

-exec :
直接对查询的结果文件进行操作,后面带的是linux命令。
{}是占位符,是文件全路径名称。

-ok: ==>exec ,但是,如果覆盖文件,他会有提示。
-inum: 10000

    find /
    find / -name "*tools.jar"
    > 支持通配符 
      * , [] .{} ,? .[mn],[a-zA-Z0-9]

     find /etc -name "*conf" 
     find /etc -name "*txt|*conf" -type f 


     find . -type f -name "*conf" -size +5k -delete

硬连接,一般不连接目录。

ln
ln source target

ln -s

s: symbol /soft

stat

stat -c %i :inode
%s: size

练习

  1. 复制 /etc/ conf结尾的文件复制到你当前目录(~)

  2. 把这些文件中大于5k,以conf结尾 文件复制到/tmp/但是,文件的尾部加上bak
    asround.conf
    /tmp/asround.conf.bak

    find . -type f -name “*conf” -size +3k -exec mv {} /tmp/{}.bak ;

find . -type d -name “*.d”
find . -perm 755
删除非link文件
find . ! -type l -delete

find / -samefile thefile
find / -inum 783232233

作者:严锋  创建时间:2024-03-22 09:09
最后编辑:严锋  更新时间:2025-05-09 15:48