首页 / 操作系统 / Linux / Linux基础知识:find命令的使用
find 命令用于查找文件系统中的指定文件。*命令格式:find pathname -option [-print -exex -ok]1.pathname要查找的目录路径~表示home目录.表示当前目录/表示根目录2.option常用的选项-name:按名称查找-perm:按文件权限查找-prune:不在当前指定目录下查找-type:按照文件类型查找-user:查找指定属主的文件或目录-group:查找指定所属组的文件或目录-nouser:查找无有效属主的文件-nogroup:查找五有效所属组的文件-depth:从指定目录下最深层的子目录开始查找-size:查找指定大小的文件3.参数-print: find命令将匹配的文件输出到标准输出。-exec: find命令对匹配的文件执行该参数所给出的shell命令。相应命令的形式为"command" { } ;,注意{ }和;之间的空格。-ok: 和-exec的作用相同,只不过以一种更为安全的模式来执行该参数所给出的shell命令,在执行每一个命令之前,都会给出提示,让用户来确定是否执行。4.使用-name选项,按名字查找在当前目录及子目录中,查找大写字母开头的txt文件
find . -name "[A-Z]*.txt" -print在/etc及其子目录中,查找host开头的文件
find /etc -name "mo*" -print在HOME目录及其子目录中,查找所有文件
find ~ -name "*" -print在当前目录及子目录中,查找不是out开头的txt文件
find . -name "d*" -prune -o -name "*.txt" -print5.按目录查找在当前目录除aa之外的子目录内搜索 txt文件
find . -path "./abc" -prune -o -name "*.txt" -print在当前目录及除aa和bb之外的子目录中查找txt文件
find . ( -path "./aa" -o -path "./bb" ) -prune -o -name "*.txt" -print在当前目录,不再子目录中,查找txt文件
find . ! -name "." -type d -prune -o -type f -name "*.txt" -print 6.按文件权限查找在当前目录及子目录中,查找属主具有读写执行,其他具有读执行权限的文件
find . -perm 755 -print7.按文件类型查找在当前目录及子目录下,查找符号链接文件
find . -type l -print在/etc目录下查找所有的符号链接文件,可以用$ find /etc -type l -print8.按属主及属组查找文件查找属主是tt的文件
find / -user tt -type f -print
查找属主被删除的文件
find / -nouser -type f -print
查找属组admin的文件
find / -group admin -type f -print
查找用户组被删掉的文件
find / -nogroup -type f -print9.按大小查找 查找超过1M的文件
$ find / -size +1M -type f -print
查找等于6字节的文件
$ find . -size 6c -print
查找小于32k的文件
$ find . -size -32k -print本文永久更新链接地址