`
haiouc
  • 浏览: 115182 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

(linux) find command

阅读更多

find命令的主要功能是在系统中查找文件或目录:
 
find命令的一般形式为:find pathname -options [-print -exec -ok]
print为对匹配文件输出到标准输出,默认为标准输出,故可不写
exec为对匹配文件执行该参数给出的shell命令,形式为'command' {} \;
ok与exec类似,更安全,每步需要用户确认。
 
1.-name 根据文件名匹配。例如:
find ~ -name "test.txt" 在home路径及子目录下查找test.txt文件。
find . -name "[a-z][A-Z][0-9][0-9]*" 在当前路径及子目录下查找,一个小写字母加一个大写字母加两个数字开头的文件。
find / -name "*.txt" 查找所有txt文件。
 
2.-perm(permission)根据权限匹配。例如:
find . -perm 777 查找当前及子目录下所有权限为777的文件。(777意义详见chmod)
find . -perm -777 查找权限大于等于777的文件。+为小于等于。
 
3.-user 根据用户匹配。例如:
find . -user abc 查找abc属主的文件。
 
4.-nouser 查找属主账户已经被删除的文件。例如:
find . -nouser
 
5.-group,-nogroup 与user,nouser类似。
 
6.-mtime 根据更改时间匹配。例如:
find . -mtime -3 3天以内的
find . -mtime +4 4天以前的
 
7.-newer 根据更改时间匹配。例如:
find . -newer abc 更改时间比abc文件新的文件。
find . -newer abc ! -newer 123 -exec ls -l {} \; 更改时间比abc新但比123旧的文件,列出其详细信息。!为逻辑非。
 
8.-type 根据文件类型匹配。
文件类型:
b:块设备文件
d:目录
c:字符设备文件
p:管道文件
l:符号链接文件
f:普通文件

例如:
find . -type f #查找普通文件
$find . -type d -name 16M_Image #查找特定目录
 
9.-size 根据文件长度匹配。例如:
find . -size +1000000c 文件大于1M字节的文件。注意数字后面的c,c代表用字节计量。
find . -size 10 文件等于512块的文件。数字后没有c时,表示用块(1块=512字节)计量。
 
10.还可与xargs命令一同使用(后续介绍)。


======================================================================================
======================================================================================
                          linux find command

==========================================

格式: find [path...] [expression]
find / -name access_log 2>/dev/null 不显示错误信息
find / -amin n ##查找系统中最后N分钟访问的文件
find / -atime n ##查找系统中最后n*24小时访问的文件
find / -cmin n ##查找系统中最后N分钟被改变状态的文件
find / -ctime n ##查找系统中最后n*24小时被改变状态的文件
find / -empty ##查找系统中空白的文件,或空白的文件目录,或目录中没有子目录的文件夹
find / -false ##查找系统中总是错误的文件
find / -fstype type ##查找系统中存在于指定文件系统的文件,例如:ext2 .
find / -gid n ##查找系统中文件数字组 ID 为 n的文件
find / -group gname ##查找系统中文件属于gnam文件组,并且指定组和ID的文件
find / -mmin n # 查找在系统中最后n分钟里修改过的文件
find / -mtime n #查找在系统中最后24*n小时里修改过的文件
find / -nouser #查找在系统中属于作废用户的文件
find / -size nc #查找在系统中长度为n字节的文件
find / -size +nc #查找在系统中长度大于n字节的文件
find / -daystart ##测试系统从今天开始24小时以内的文件,用法类似-amin
find / -depth ##使用深度级别的查找过程方式,在某层指定目录中优先查找文件内容
find / -follow ##遵循通配符链接方式查找; 另外,也可忽略通配符链接方式查询
find / -help ##显示命令摘要
find / -maxdepth levels ##在某个层次的目录中按照递减方法查找
find / -mount ##不在文件系统目录中查找, 用法类似 -xdev.
find / -noleaf ##禁止在非UNUX文件系统,MS-DOS系统,CD-ROM文件系统中进行最优化查找

find / -version ##打印版本数字
-exec command; ##查找并执行命令
-fprint file ##打印文件完整文件名
-fprint0 file ##打印文件完整文件名包括空的文件
-fprintf file format ##打印文件格式
-ok command; ##给用户命令执行操作,根据用户的Y 确认输入执行
-printf format ##打印文件格式
-ls ##打印同种文件格式的文件.

几个参数之间可以用-and,-or连接,某个参数取反可用!
======================
用man find可以看到下面的说明:
-mtime n 
   Files data was last modified n*24 hours ago.  ===>  man find里面解释错误
find -mtime 4 是找到所有5天前4天后被更改的档案文件,
find -mtime -4 是4天内被改的档案,
find -mtime +4 是4天后被改的档案。
======================

查看某目录下有多少个文件命令:
# find DirPath -type f | wc -l
比如: find /home/snail -type f | wc -l

如果想查看 src 目录下有多少 C 文件,如下:
# find ./src -type f -name "*.c" | wc -l

find 命令的 -type 后的参数有以下选择,每种都代表不一样的“类型(type)”
-type 文件类型
        b      块文件(比如内存)
        c      字符文件(比如串口)
        d      目录文件(目录也是一种文件)
        p      有名管道(FIFO)
        f      普通文件
        l      符号链接(如果使用 -L 或 -follow 选项则不起作用,除非链接损坏)
        s      socket文件(比如 /tmp/mysql.sock)
        D      door (Solaris)

======================
文件查找命令  find
find 用于查找文件系统中指定文件,其格式为: find 要查找的路径 表达式
例如:  find . -name 1.txt        \\ 在当前目录及其子目录下查找文件1.txt
find /tmp -name 1.txt     \\ 在/tmp 目录及其子目录下查找文件1.txt

======================

查找Linux下的空目录技巧

if [ -z "$1" ]; then
 echo Usage: $0 \
 exit 1
fi
echo -e Null directory list:
for i in $(find $1 -type d -print)

do
 TMP=$(ls $i)
 if [ "$TMP" = "\." ]; then
  continue
 elif [ -z "$TMP" ]; then
  echo $i
 fi
done

 

======================

分享到:
评论

相关推荐

    the linux command line

    Slice and dice text files with cut, paste, grep, patch, and sed Once you overcome your initial 'shell shock,' you'll find that the command line is a natural and expressive way to communicate with your...

    The Linux Command Line

    Slice and dice text files with cut, paste, grep, patch, and sed Once you overcome your initial 'shell shock,' you'll find that the command line is a natural and expressive way to communicate with your...

    Linux命令搜索工具linux-command.zip

    linux-command Linux命令大全搜索工具,内容包含Linux命令手册、详解、学习、搜集。   Linux命令分类 这里存放Linux 命令大全并不全,你可以通过linux-command来搜索,它是把 command ...

    The Linux Command Line: A Complete Introduction, 2nd Edition(Linux命令行大全,第二版)

    Once you overcome your initial "shell shock," you'll find that the command line is a natural and expressive way to communicate with your computer. Just don't be surprised if your mouse starts to ...

    Linux find命令用法详解

    find path -option [ -print ] [ -exec -ok command ] {} \; 参数说明 : find 根据下列规则判断 path 和 expression,在命令列上第一个 – ( ) , ! 之前的部份为 path,之后的是 expression。如果 path 是空字串则

    An A-Z Index of the Linux Command LIne

    linux 命令一览表 alias Create an alias • apropos Search Help manual pages (man ­k) apt­get Search for and install software packages (Debian/Ubuntu) aptitude Search for and install software ...

    linux find命令之exec简单概述

    find是我们很常用的一个Linux命令,但是我们一般查找出来的并不仅仅是看看而已,还会有进一步的操作,这个时候exec的作用就显现出来了。 exec解释: -exec 参数后面跟的是command命令,它的终止是以;为结束标志的,...

    Linux中find常见用法示例

    ·find path -option [ -print ] [ -exec -ok command ] {} ;  find命令的参数;  pathname: find命令所查找的目录路径。例如用.来表示当前目录,用/来表示系统根目录。  -print: find命令将匹配的...

    opatch139400.zip

    该为weblogic12.2.1.3版本opatch13.9.4.0.0升级包,另外weblogic漏洞升级说明文档在我另外一个资源包里

    Linux之find 命令

    Linux find命令用来在指定目录下查找文件。任何位于参数之前的字符串都将被视为欲查找的目录名。如果使用该命令时,不设置任何参数,则find命令将在当前目录下查找子目录与文件。并且将查找到的子目录和文件全部进行...

    Linux for Beginners: An Introduction to the Linux Operating System

    The file system layout of Linux systems and where to find programs, configurations, and documentation. The basic Linux commands you'll use most often. Creating, renaming, moving, and deleting ...

    Linux Pocket Guide

    Throw in a host of valuable power user tips and a friendly and accessible style, and you'll quickly find this practical, to-the-point book a small but mighty resource for Linux users.

    Linux 基本指令

    brief Linux command that will moreeasy to find

    busybox command help.pdf

    BusyBox 是一个集成了三百多个最常用Linux命令和工具的软件。BusyBox 包含了一些简单的工具,例如ls、cat和echo等等,还包含了一些更大、更复杂的工具,例grep、find、mount以...

    Learn Raspberry Pi with Linux(Apress,2013)

    Learn Raspberry Pi with Linux will tell you everything you need to know about the Raspberry Pi's GUI and command line so you can get started doing amazing things. You'll learn how to set up your new ...

    英文原版-Learn Linux in a Month of Lunches 1st Edition

    In easy-to-follow lessons designed to take an hour or less, you'll learn how to use the command line, along with practical topics like installing software, customizing your desktop, printing, and ...

    vmtools-linux.iso

     这时我们并没有真正的安装上了VMWARE TOOLS软件包,如果您点击菜单:DEVICES,您就会发现光驱的菜单文字变为:ide1:0-> C:\Program Files\VMware\VMware Workstation\Programs\linux.iso,这表示VMWARE将LINUX的ISO...

    Linux Administration: A Beginner's Guide, Fifth Edition

    But this is no mere command reference or novice's introduction. Shah doesn't shy away from explaining the really interesting aspects of Linux administration, including kernel compilation, Domain Name ...

    Learn Linux in a Month of Lunches

    You'll find a road map to the commands and processes you need to be instantly productive. What's Inside Master the command line Learn about file systems Understand desktop environments Go from ...

    node-v59-linux-x64-glibc/grpc_node.node

    Cannot find module '/home/user/.nvm/versions/node/v8.11.3/lib/node_modules/composer-cli/node_modules/grpc/src/node/extension_binary/node-v59-linux-x64-glibc/grpc_node.node'

Global site tag (gtag.js) - Google Analytics