find 常用参数

find 常用参数

查找命令

find 、which、whereis、locate

其中which whereis 从$PATH中去搜索,而locate需要下载安装yum -y install mlocate,初次运行locate会报错,第一次使用会先生成文件列表库

updatedb手动更新库

find:


  -ctime +/-n   #n表示大于/小于 n 访问天数

  -mtime +/-n

  -atime +/-n

  -name

  -type f/[l,s..b、c、d]

  -c[m、a]min n  #分钟

  -size

  -inum #搜索inode号的文件
  • atime #访问时间

  • mtime #内荣修改时间

  • ctime #内容和属性修改时间,其中mtime变了,ctime也就变了


[root@xujb01 test]# touch txt
[root@xujb01 test]# stat txt
  File: 'txt'
  Size: 0             Blocks: 0          IO Block: 4096   regular empty file
Device: 802h/2050d    Inode: 914317      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Context: unconfined_u:object_r:user_tmp_t:s0
Access: 2017-10-28 09:26:59.649167076 +0800
Modify: 2017-10-28 09:26:59.649167076 +0800
Change: 2017-10-28 09:26:59.649167076 +0800
 Birth: -

修改atime----------------------------------------------------------------

[root@xujb01 test]# cat txt           
[root@xujb01 test]# stat txt
  File: 'txt'
  Size: 0             Blocks: 0          IO Block: 4096   regular empty file
Device: 802h/2050d    Inode: 914317      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Context: unconfined_u:object_r:user_tmp_t:s0
Access: 2017-10-28 09:28:09.339172222 +0800          #cat 查看了文件atime时间变化了
Modify: 2017-10-28 09:26:59.649167076 +0800
Change: 2017-10-28 09:26:59.649167076 +0800

 Birth: -

修改mtime而产生ctime变化------------------------------------------------------------------------------

[root@xujb01 test]# echo "hello 01" > txt
[root@xujb01 test]# stat txt
  File: 'txt'
  Size: 9             Blocks: 8          IO Block: 4096   regular file
Device: 802h/2050d    Inode: 914317      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Context: unconfined_u:object_r:user_tmp_t:s0
Access: 2017-10-28 09:28:09.339172222 +0800
Modify: 2017-10-28 09:29:22.921345202 +0800                       #修改了内容mtime 和 ctime 时间都更新了而atime时间没有更新
Change: 2017-10-28 09:29:22.921345202 +0800
 Birth: -

只修改ctime----------------------------------------------------------------------------

[root@xujb01 test]# chmod +x txt
[root@xujb01 test]# stat txt
  File: 'txt'
  Size: 9             Blocks: 8          IO Block: 4096   regular file
Device: 802h/2050d    Inode: 914317      Links: 1
Access: (0755/-rwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Context: unconfined_u:object_r:user_tmp_t:s0
Access: 2017-10-28 09:28:09.339172222 +0800
Modify: 2017-10-28 09:29:22.921345202 +0800
Change: 2017-10-28 09:31:40.687285888 +0800               #修改了文件属性ctime 时间更新了但是mtime 和 atime 都不会有变化
  • -name 搜索

[root@xujb01 test]# find / -name txt
/tmp/test/test/txt
  • -type 搜索

[root@xujb01 test]# ls;find . -type l      #搜索软链接文件
linktxt  test01  testtxt  txt  txttest
./linktxt             

[root@xujb01 test]# find . -type l -exec ls -al --color=auto {} \;         #-exec调用并执行指令 不能用alias的内容所以 ll 会报错
lrwxrwxrwx. 1 root root 3 Oct 28 09:41 ./linktxt -> txt
  • -c[m、a]min n #分钟


  • -size +/-M[k,G]

[root@xujb01 test]# ll -h
total 72K
-r--------. 1 root root  64K Oct 28 10:02 kcore
lrwxrwxrwx. 1 root root    3 Oct 28 09:41 linktxt -> txt
drwxr-xr-x. 2 root root 4.0K Oct 28 09:38 test01
-rw-r--r--. 1 root root    0 Oct 28 09:35 testtxt
-rwxr-xr-x. 1 root root    9 Oct 28 09:29 txt
-rw-r--r--. 1 root root    0 Oct 28 09:34 txttest

*****************************************************

[root@xujb01 test]# find . -type f -size +1k -exec ls -l {} \;          #连续两个参数 `-type` `-size` 是且的意思那有没有**或**呢

-r--------. 1 root root 65536 Oct 28 10:02 ./kcore

[root@xujb01 test]# find . -amin +15 -o -size +1k -exec ls -dl {} \;        #-o 表示或的意思
drwxrwxrwt. 3 root root 4096 Oct 28 10:02 .
-r--------. 1 root root 65536 Oct 28 10:02 ./kcore
  • -inum

[root@xujb01 test]# ll -i
total 72
914360 -r--------. 1 root root 65536 Oct 28 10:02 kcore
914359 lrwxrwxrwx. 1 root root     3 Oct 28 09:41 linktxt -> txt
914358 drwxr-xr-x. 2 root root  4096 Oct 28 09:38 test01
914357 -rw-r--r--. 1 root root     0 Oct 28 09:35 testtxt
914317 -rwxr-xr-x. 1 root root     9 Oct 28 09:29 txt
914340 -rw-r--r--. 1 root root     0 Oct 28 09:34 txttest

[root@xujb01 test]# find /tmp -inum 914360     #可以用来找硬链接文件
/tmp/test/test/kcore

[root@xujb01 test]# ln txt test05

[root@xujb01 test]# find / -inum 914317 -exec ls -i {} \;
914317 /tmp/test/test/test05
914317 /tmp/test/test/txt

-exec ls -i {} \; #和find 连用 {}为前面find的内容ls 为执行的命令 后面\;为格式 期间空格需要严格按照要求

posted on 2017-10-28 10:26  游荡的鱼  阅读(362)  评论(0编辑  收藏  举报

导航