Find 常用命令的使用 (上)



Find 用来查找某个目录或者文件 

 

语法  find [-H] [-L] [-P] [-D debugopts] [-Olevel] [path...] [expression] 


常用选项  


一、按类型来查找    


-type         ( f 文件、d目录、b块文件、s sock 文件 )


举例说明  

root@localhost:~# find /home/bob/ -type d   #查找目录下面的文件夹

/home/bob/

/home/bob/moudle


root@localhost:~# find /home/bob/ -type f   #查找目录下面的文件


/home/bob/1.html

/home/bob/5.html


root@localhost:~# find /dev/ -type b  #查找目录下面的块文件

/dev/xvda1

/dev/xvda


二、按名字来查找


-name 


root@localhost:~# find /home/bob/ -name *.html  #查找当前目录下面所有html 文件


/home/bob/1.html

/home/bob/5.html


三、按大小来查找 

-size  

root@localhost:~# find /boot/ -size +10M    # 大于10M的文件 

/boot/initrd.img-3.2.0-67-generic



四、按时间来查找 


ctime  改变时间    #-n指n天以内,+n指n天以前


mtime  修改时间   #-n指n天以内,+n指n天以前


atime  访问时间   #按文件访问时间来查


注释 mtime和ctime 的区别是 前者改变的是文件的具体内容、后者改变的是文件的属性 



举例说明  


bob@localhost:~$ ls -lc a.txt   显示文件的ctime 

-rw-rw-r-- 1 bob bob 0 May  6 14:22 a.txt

bob@localhost:~$ ls -lu a.txt   显示文件的atime 

-rw-rw-r-- 1 bob bob 0 May  6 14:22 a.txt

bob@localhost:~$ ls -l a.txt   显示文件的 mtime 

-rw-rw-r-- 1 bob bob 0 May  6 14:22 a.txt


其他常见选项


find /home/bob/ -amin -5    # 查找在系统中最后5分钟访问的文件

find /usr/local/ -atime -1       # 查找在系统中最后24小时访问的文件

find    /   -empty             # 查找在系统中为空的文件或者文件夹

find    /   -group   cat        # 查找在系统中属于 groupcat的文件

find /home/bob/ -mmin   -5        # 查找在系统中最后5分钟里修改过的文件

find /home/bob/ -mtime -1        #查找在系统中最后24小时里修改过的文件


你可能感兴趣的:(find)