• 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" -print

    5.按目录查找

    在当前目录除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 -print

    7.按文件类型查找

    在当前目录及子目录下,查找符号链接文件
    find . -type l -print

    在/etc目录下查找所有的符号链接文件,可以用

    $ find /etc -type l -print

    8.按属主及属组查找文件

    查找属主是tt的文件  
    find / -user tt -type f -print  
    查找属主被删除的文件
    find / -nouser -type f -print  
    查找属组admin的文件
    find / -group admin -type f -print  
    查找用户组被删掉的文件
    find / -nogroup -type f -print

    9.按大小查找  

    查找超过1M的文件
    $ find / -size +1M -type f -print  
    查找等于6字节的文件
    $ find . -size 6c -print  
    查找小于32k的文件
    $ find . -size -32k -print

     

  • 相关阅读:
    约瑟夫问题
    LCIS(最长公共上升子序列)
    Spfa求负环
    裴蜀(贝祖)定理
    Tarjan算法之简单缩点
    树形dp-二次扫描+换根
    sys.path.insert
    python学习之路(十二)
    python学习之路(十一)
    python学习之路(十)
  • 原文地址:https://www.cnblogs.com/BaoLeri/p/5837947.html
Copyright © 2020-2023  润新知