(Linux 学习十二)文件查找(上)

文件查找

javascript 复制代码
which   命令查找  也可以用 whereis
find    文件查找,针对文件名
locate  文件查找,依赖数据库




alias  别名
alias  yyy ='ls --color=auto -l'
yyy //相当于别名  查看文件


which  ls  //查找ls 命令位置
whereis  vim  //也是查找命令


locate 123.txt  //查找123.txt文件位置

别名

find常用命令

javascript 复制代码
find  [path...]  [options]   [expression] [action]
命令    路径        选项        表达式        动作


例子:
按文件名查找:
find /etc  -name  "hosts"  //查找文件名字包含hosts
find /etc  -iname  "Hosts"  //  -i  忽略大小写
find  /etc -iname  "Hos*"   //查找



按文件大小查找:
find /etc -size +5M   //大于5M的文件
find  /etc -size 5M   //等于5M的文件
find /etc  -size -5M   //小于5M的文件



指定查找的目录深度:
find  /   -maxdepth 3 -a -name "ifcfg-en*" //最大查找3级


按文件属主、属组查找:
find /home -user yyy  //属yyy的文件
find /home -group hr   //属组hr的文件

按文件类型:
find  /dev -type  f   //查找普通文件  f
find /dev -type  d  //查找目录  d
find /dev -type  b  //设备 b

按文件权限:
find -perm  644 -ls  //查找权限644
find -perm  700 -ls  //查找权限700


找到后处理的动作actions
find /ect -name "123*"   -delete  //查找文件 后删除
find /etc  -name "yyy*"  -ok   cp -rvf {}  /tmp \;
//查找yyy文件   ok连接符
//cp复制     rvf r递归 v显示复制进度  f强制覆盖目标文件或目录
// {}占位符 源文件 前面查出来的所有文件    /tmp 复制到目标目录
// \;结束符
相关推荐
甲鱼92932 分钟前
MySQL 实战手记:日志管理与主从复制搭建全指南
运维
Johny_Zhao15 小时前
OpenClaw安装部署教程
linux·人工智能·ai·云计算·系统运维·openclaw
YuMiao1 天前
gstatic连接问题导致Google Gemini / Studio页面乱码或图标缺失问题
服务器·网络协议
chlk1232 天前
Linux文件权限完全图解:读懂 ls -l 和 chmod 755 背后的秘密
linux·操作系统
舒一笑2 天前
Ubuntu系统安装CodeX出现问题
linux·后端
改一下配置文件2 天前
Ubuntu24.04安装NVIDIA驱动完整指南(含Secure Boot解决方案)
linux
碳基沙盒2 天前
OpenClaw 多 Agent 配置实战指南
运维
深紫色的三北六号3 天前
Linux 服务器磁盘扩容与目录迁移:rsync + bind mount 实现服务无感迁移(无需修改配置)
linux·扩容·服务迁移
SudosuBash3 天前
[CS:APP 3e] 关于对 第 12 章 读/写者的一点思考和题解 (作业 12.19,12.20,12.21)
linux·并发·操作系统(os)
哈基咪怎么可能是AI3 天前
为什么我就想要「线性历史 + Signed Commits」GitHub 却把我当猴耍 🤬🎙️
linux·github