Linux文件查找

1.简介

which :命令查找
find: 文件查找,针对文件名
locate:文件查找,依赖数据库
一、命令文件查找
1.查找ls 命令的位置
which ls //从PATH环境变量或者whereis vim
二、任意文件
locate
1.locate查找文件hosts文件
[root@localhost ~]# locate hosts
2.更新locate数据库
[root@localhost ~]# updatedb

一.find 查找

语法
find [path…] [options] [expression] [action]
命令 路径 选项 表达式 动作
1.按文件名:
[root@localhost ~]# find /etc -name “hosts”
[root@localhost ~]# find /etc -iname “hosts”
[root@localhost ~]# find /etc -iname “hos*”
-i忽略大小写
2.按文件大小查找:
[root@localhost ~]# find /etc -size +5M
[root@localhost ~]# find /etc -size 5M
[root@localhost ~]# find /etc -size -5M
文件>5M
文件=5M
文件<5M
3.指定查找的目录深度:
可查找范围

[root@localhost ~]# find / -maxdepth 4 -a -name “ifcfg-en*”
查询是成功的

不可查找范围
[root@localhost ~]# find / -maxdepth 3 -a -name “ifcfg-en*”
查询是失败的
4.按文件属主、属组找:
[root@localhost ~]# find /home -user jack //属主是jack的文件
[root@localhost ~]# find /home -group hr //属组是hr组的文件
5.按文件类型:
[root@localhost ~]# find /tmp -type f
[root@localhost ~]# find /dev -type b
f普通文件
b块设备文件
d目录
p管道
l连接
6.按文件权限:
[root@localhost ~]# find . -perm 644 -ls
-ls 是find的动作之一,精确权限
找到后处理的动作 ACTIONS:
7.找到后默认是显示文件
[root@localhost ~]# find . -perm 715 -print
-print显示文件名
[root@localhost ~]# find . -perm 715 -ls
-ls显示文件属性
找到后删除
[root@localhost ~]# find /etc -perm “775*” -delete
找到后复制
[root@localhost ~]# find /etc -name “ifcfg*” -ok cp -rvf {} /tmp \;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值