Linux find命令傻瓜入门

作者: mst7 | 来源:发表于2016-04-27 18:28 被阅读650次

命令格式:find <PATH> <OPTION> <ACTION>

<PATH>

默认为当前目录

<OPTION>

默认查找指定路径下的所有文件
-name "filename" 按名字检索文件
-iname 'filename' 按名字检索文件,不区分大小写。名字可以使用通配符:

* 任意长度的任意字符
? 任意的单个字符
[] 选项内的字符

-type "" 检索文件的类型

f:普通文件
d: 目录
c: 字符
b: 块设备
l: 链接
p: 管道
s: 套接字

-maxdepth #NUMBER 检索目录深度,配置为1则只检索第一级目录
-regex pattern 基于正则表达式进行文件名匹配
-user username :根据属主查找
-group groupname :根据属组查找
-gid gid:根据gid查找
-uid uid::根据udi查找
-nouser 查找没有属主的文件
-nogroup 没有属组的文件

<ACTION>

默认为显示到console
-print 默认-ls:类似 ls -l的形式显示文件的每一个信息
-ok command {} ; 会每次执行进行询问操作,需要用户确认
-exec command {} ; 不会惊醒询问操作

find与xarg (此小节内容是完全引用他人的)

xargs: 作用是将参数列表转换成小块分段传递给其他命令,以避免参数列表过长的问题。
相较于-exec command 而言,此命令功能更强悍。和find合用的时候,一般是通过管道传递给xargs
find /tmp –size +100M | xargs ‘rm –rf '

实例

**find . -maxdepth 1 -name ".*" **查找当前目录下的隐藏文件和目录

ray@ray-ThinkPad-X250:~$ find . -maxdepth 1 -name ".*"
.
./.gnome2
./.swp
./.webex
./.config
./.gnome
./.xsession-errors.old
./.systemtap
./.nixnote

**find . -maxdepth 1 -iname "*app*" **查找当前目录下所有包含“app”字符的文件或目录,不区分大小写

ray@ray-ThinkPad-X250:~$ find . -maxdepth 1 -iname "*app*"
./Applications

**find /home/ -name "*.desktop" **查找当前目录及其子目录下的所有.desktop文件

ray@ray-ThinkPad-X250:~$ find /home/ -name "*.desktop"
/home/ray/.config/autostart/telepathy-indicator.desktop
/home/ray/.config/autostart/gnome-user-share-webdav.desktop
/home/ray/.config/autostart/ulogme.desktop
/home/ray/examples.desktop
/home/ray/.gnome/apps/chrome-nmmhkkegccagdldgiimedpiccmgmieda-Default.desktop
/home/ray/.gnome/apps/chrome-apdfllckaahabafndbhieahigkjlhalf-Default.desktop

**find . -name "*theme*" -type d **查找当前目录及其子目录下所有的包含“theme”字符的目录

ray@ray-ThinkPad-X250:~$ find . -name "*theme*" -type d
./.vim/plugins/vim-airline/autoload/airline/themes
./Downloads/debs/theme
./Downloads/debs/theme/arc-theme
./Downloads/debs/theme/arc-theme/extra/Chrome/arc-theme
./Downloads/debs/theme/arc-theme/extra/Chrome/arc-darker-theme
./.local/share/themes

find . -maxdepth 1 -iname "*app*" -exec ls -d {} ; 查找当期目录下名字包含"app"字符(不去分大小写)的目录或文件,并通过命令ls -d 显示出来。

ray@ray-ThinkPad-X250:~$ find . -maxdepth 1 -iname "*app*" -exec ls -d {} \;
./Applications
ray@ray-ThinkPad-X250:~$ 

find . -maxdepth 1 -iname "*app*" | xargs ls -d 实现的结果与上一条一样

ray@ray-ThinkPad-X250:~$ find . -maxdepth 1 -iname "*app*" | xargs ls -d
./Applications

参考URL

http://blog.chinaunix.net/uid-24648486-id-2998767

相关文章

  • Linux find命令傻瓜入门

    命令格式:find 默认为当前目录

  • Linux find命令查找文件

    Linux Find命令 Linux find命令用来在指定目录下查找文件。 学习参考地址:https://www...

  • Linux find and grep

    linux下的find文件查找命令与grep文件内容查找命令 linux下的find文件查找命令与grep文件内容...

  • find--linux

    Linux中find常见用法示例(转) find命令的参数; pathname: find命令所查找的目录路径。例...

  • 基础篇

    Linux学习 一、find命令 1、搜索文件的命令:which、whereis、locate、find a、wh...

  • linux 命令行整理2

    这次我们来看看Linux的查找文件的命令:find 命令格式: find 范围 匹配条件 比如:find /etc...

  • 2019-08-08Linux高阶命令与虚拟机上网的问题

    1.Linux命令 1.1find命令 在Linux文件系统中,用来查找一个文件放在哪。find /etc -n...

  • 碎碎念 b

    Linux中的搜索命令 文件搜索命令locate 命令搜索命令 忘记是啥了 find命令,其中find命令有好多后...

  • 每日总结-第十五天-linux

    linux find命令 题外:好像成了Linux命令汇总帖子hhh(菜哭)https://www.cnblogs...

  • Mac 常用操作

    一、常用命令 Linux的五个查找命令:find,locate,whereis,which,type 1、find...

网友评论

    本文标题:Linux find命令傻瓜入门

    本文链接:https://www.haomeiwen.com/subject/civcrttx.html