find 命令_find命令扩展

 find命令扩展

为什么要使用find命令?

    Linux系统中有着成千上万的文件,如果你想要找到自己想要的文件,一款查找软件是必不可少的,而locate是根据其生成的数据库进行查找,虽然速度会略快,但非实时查找,有些新的文件或目录是匹配不到的,而且locate是模糊匹配,而find命令为实时查找,且为精确匹配,如果你对目录的权限够大,想查什么就查什么!

find命令的语法格式:

    find  [查找路径] [查找条件] [处理动作]

1.1 方法一 |xargs

通过|xargs将前面命令的执行结果传给后面。

[root@master ]# find /opt/ -type f -name "*.sh" |xargs ls -l

-rw-r--r--. 1 root root 7 Aug 17 17:00 /opt/test/del.sh

-rw-r--r--. 1 root root 8 Aug 17 19:35 /opt/test.sh

-rw-r--r--. 1 root root 7 Aug 17 17:00 /opt/t.sh

1.2 方法二 $()

$()先运行里面的命令,把显示到屏幕上的结果留下来

[root@master]# ls -l $(find /opt/ -type f -name "*.sh")

-rw-r--r--. 1 root root 7 Aug 17 17:00 /opt/test/del.sh

-rw-r--r--. 1 root root 8 Aug 17 19:35 /opt/test.sh

-rw-r--r--. 1 root root 7 Aug 17 17:00 /opt/t.sh

1.3 方法三 -exec {} \;

-exec 是find 里面自带参数,{}表示find命令找到的文件

[root@master]# find /opt/ -type f -name "*.sh" -exec ls -l {} \;

-rw-r--r--. 1 root root 7 Aug 17 17:00 /opt/t.sh

-rw-r--r--. 1 root root 8 Aug 17 19:35 /opt/test.sh

-rw-r--r--. 1 root root 7 Aug 17 17:00 /opt/test/del.sh

[root@master]# find /aaemzl/ -type f -name "*.sh"-exec ls -l {} \; 

-rw-r--r-- 1 root root 5 Oct 12 01:10 /aaemzl/test/del.sh

-rw-r--r-- 1 root root 5 Oct 12 01:10 /aaemzl/test.sh

-rw-r--r-- 1 root root 5 Oct 12 01:10 /aaemzl/t.sh

51a639a8d273254411caef2dfbca8360.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值