Linux文件查找相关知识

Linux文件查找相关知识
(一)简介
which :命令查找
find: 文件查找,针对文件名;
locate:文件查找,依赖数据库
find: 文件查找,针对文件名;locate:文件查找,依赖数据库
(二)命令查找
查找ls 命令的位置
#which ls //从PATH环境变量 which 直接跟命令会显示其绝对路径有别名时会显示其别名(alias)
标题 whereis ls 和which差不多
(三)命令文件查找
find
1 语法
find [path…] -[options] [expression] [action]
命令 路径 选项 表达式(描述 ) 动作
2 按文件名找
[root@tianyun ~]# find /etc -name “hosts”
[root@tianyun ~]# find /etc -iname “HOSTS” //-i忽略大小写
[root@tianyun ~]# find /etc -iname “hos*” //只要含有hos就会找出来

alias别名系统使用(类似创建命令)
alias xxx=‘ 命令内容’
xxx:你想要的随意字符
-h人性化单位

3 按文件大小
[root@tianyun ~]# find /etc -size +5M //大于5M
[root@tianyun ~]# find /etc -size 5M //等于5M
[root@tianyun ~]# find /etc -size -5M //小于5M
[root@tianyun ~]# find /etc -size +5M -ls //-ls找到的处理动作

4指定查找的目录深度:
-maxdepth levels
-mindepth levels
[root@tianyun ~]# find / -maxdepth 3 -a -name “ifcfg-en*”
[root@tianyun ~]# find / -maxdepth 4 -a -name “ifcfg-en*”
数字是几级
-a是and 和的意思

5按文件属主、属组找:
[root@tianyun ~]# find /home -user jack //属主是jack的文件
[root@tianyun ~]# find /home -group hr //属组是hr组的文件

[root@tianyun ~]# find /home -nouser //缺失UID的文件

6按文件类型(了解)
[root@tianyun ~]# find /dev -type f //f普通
[root@tianyun ~]# find /dev -type d //d目录

[root@tianyun ~]# find /dev -type l //l链接
[root@tianyun ~]# find /dev -type b //b块设备
[root@tianyun ~]# find /dev -type c //c字符设备
[root@tianyun ~]# find /dev -type s //s套接字
[root@tianyun ~]# find /dev -type p //p管道文件

7 按文件权限:
普通权限、
[root@tianyun ~]# find . -perm 644 -ls //-ls是动作之一 精确权限
[root@tianyun ~]# find . -perm -644 -ls //包含权限即可
8找到后处理的动作 ACTIONS:
(1)类型
-print 打印,默认选项
-ls
-delete
-exec 后面跟自定义的shell命令
-ok 后面跟自定义的shell命令
(2)实例
find /etc -name “ifcfg*”
#find /etc -name “ifcfg*” -print
#find /etc -name “ifcfg*” -ls
find /etc -name “775*” -delete /775.txt是自定义文件
find /etc -name “ifcfg*” -exec cp -rvf {} /tmp ; //不提示
find /etc -name “775*” -exec rm -rf {} ;
find /etc -name “ifcfg*” -ok cp -rvf {} /tmp ; //提示 复制
-ok连接符 {}代表前面找到的文件是源文件 \结束符

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值