find命令详解 linux下find命令的使用方法
find命令
一般格式: find + 目录名称 + 参数
(资料图片)
@1参数的含义:-name #文件名称
实验1:按照文件名查找
##查找/etc目录中文件名为passwd的文件[root@localhost ~]# find /etc/ -name passwd/etc/passwd/etc/pam.d/passwd##查找/etc目录中文件名以.conf文件结尾的文件[root@localhost mnt]# find /etc/ -name *.conf
@2参数含义:-not #非,取反-user #文件所有人-group #文件所有组-a #并且关系-o #或者关系
实验2:按文件所有人和文件所有组查找
[root@localhost ~]# cd /mnt##建立文件[root@localhost mnt]# touch file{1..5}[root@localhost mnt]# lsfile1 file2 file3 file4 file5
监控:
[root@localhost mnt]# watch -n 1 ls -l /mnt
[root@localhost ~]# id studentuid=1000(student) gid=1000(student) groups=1000(student),10(wheel)[root@localhost ~]# id westosuid=1001(westos) gid=1001(westos) groups=1001(westos)##更改文件的所有人和所有组[root@localhost ~]# chown student.student /mnt/file1##更改文件的所有组[root@localhost ~]# chgrp westos /mnt/file2[root@localhost ~]# chown student.westos /mnt/file3
##按文件的所有人查找[root@localhost ~]# find /mnt -user student /mnt/file1/mnt/file3##按文件的所有组查找[root@localhost ~]# find /mnt -group westos/mnt/file2/mnt/file3##默认表示并且[root@localhost ~]# find /mnt -user root -group westos/mnt/file2## -a表示并且[root@localhost ~]# find /mnt -user root -a -group westos/mnt/file2## -o表示或者[root@localhost ~]# find /mnt -user root -o -group westos/mnt/mnt/file2/mnt/file3/mnt/file4/mnt/file5## -not表示非;即反向选择[root@localhost ~]# find /mnt -not -user student /mnt/mnt/file2/mnt/file4/mnt/file5
@3参数含义:-maxdepth #最大深度-mindepth #最小深度
实验3:按文件所在的深度(层次)查找
##-maxdepth表示最大深度,即最多层次[root@localhost ~]# find /etc/ -maxdepth 1 -name passwd/etc/passwd[root@localhost ~]# find /etc/ -maxdepth 2 -name passwd/etc/passwd/etc/pam.d/passwd##-mindepth表示最小深度,即最少层次[root@localhost ~]# find /etc/ -mindepth 2 -name passwd/etc/pam.d/passwd[root@localhost ~]# find /etc/ -mindepth 1 -name passwd/etc/passwd/etc/pam.d/passwd##查找/etc目录下最少层次为1最多层次为2的以.conf结尾的文件[root@localhost ~]# find /etc/ -mindepth 1 -maxdepth 2 -name *.conf
@4参数含义: -size 表示文件大小 -size 20K # 查找大小为20K的文件 -size -20K # -表示小于;查找比20K小的文件 -size +20k # +表示大于;查看比20K大的文件
实验4:按文件的大小查找
[root@localhost ~]# cd /mnt[root@localhost mnt]# rm -rf *[root@localhost mnt]# ls##dd表示截取,if输入,of输出[root@localhost mnt]# dd if=/dev/zero of=file1 bs=1 count=1024010240+0 records in10240+0 records out10240 bytes (10 kB) copied, 0.0113629 s, 901 kB/s##查看文件所占磁盘的大小[root@localhost mnt]# du -sh file112Kfile1[root@localhost mnt]# dd if=/dev/zero of=file2 bs=1 count=2048020480+0 records in20480+0 records out20480 bytes (20 kB) copied, 0.0198726 s, 1.0 MB/s[root@localhost mnt]# du -sh file220Kfile2[root@localhost mnt]# dd if=/dev/zero of=file3 bs=1 count=4096040960+0 records in40960+0 records out40960 bytes (41 kB) copied, 0.0397736 s, 1.0 MB/s[root@localhost mnt]# du -sh file340Kfile3
[root@localhost mnt]# ll -ltotal 72-rw-r--r--. 1 root root 10240 Nov 11 04:06 file1-rw-r--r--. 1 root root 20480 Nov 11 04:06 file2-rw-r--r--. 1 root root 40960 Nov 11 04:06 file3##查找/mnt目录下文件大小为20k的文件[root@localhost mnt]# find /mnt/ -size 20k/mnt/file2##查找/mnt目录下比20k小的文件[root@localhost mnt]# find /mnt/ -size -20k/mnt//mnt/file1##查找/mnt目录下比20k大的文件[root@localhost mnt]# find /mnt/ -size +20k/mnt/file3
@5参数含义:-type #文件类型主要的文件类型: f #普通文件 d #目录 b #块设备 s #套接字 c #字符设备 l #链接 p #管道
实验5:按文件类型查找
##f表示普通文件[root@localhost ~]# find /dev -type f/dev/shm/pulse-shm-620843697/dev/shm/pulse-shm-1247103260/dev/shm/pulse-shm-2690706600/dev/shm/pulse-shm-368331657##b表示块设备[root@localhost ~]# find /dev -type b/dev/dm-0/dev/sr0/dev/vdb1/dev/vdb/dev/vda1/dev/vda##s表示套接字[root@localhost ~]# find /dev -type s/dev/log##p表示管道[root@localhost ~]# find /dev -type p/dev/initctl[root@localhost ~]# find /mnt -type f/mnt/file1/mnt/file3/mnt/file2##d表示目录[root@localhost ~]# find /mnt -type d/mnt
@6参数含义:-perm 表示权限-perm 444 #查找文件权限-perm -444 # -表示并且;查找文件权限中u位有r权限,并且g位有r权限,并且o位有r权限的文件-perm /444 # /表示或者;查找文件权限中u位有r权限,或者g位有r权限,或者o位有r权限的文件-perm /777 # 777=rwx rwx rwx 即9个条件中满足任意一个即可
实验6:按文件权限查找
[root@localhost ~]# cd /mnt[root@localhost mnt]# rm -rf *[root@localhost mnt]# ls##建立文件[root@localhost mnt]# touch file{1..3}[root@localhost mnt]# lltotal 0-rw-r--r-- 1 root root 0 Nov 14 09:41 file1-rw-r--r-- 1 root root 0 Nov 14 09:41 file2-rw-r--r-- 1 root root 0 Nov 14 09:41 file3##更改文件权限[root@localhost mnt]# chmod 777 /mnt/file1[root@localhost mnt]# chmod 404 /mnt/file2[root@localhost mnt]# chmod 400 /mnt/file3[root@localhost mnt]# lltotal 0-rwxrwxrwx 1 root root 0 Nov 14 09:41 file1-r-----r-- 1 root root 0 Nov 14 09:41 file2-r-------- 1 root root 0 Nov 14 09:41 file3
##查找文件权限为404的文件[root@localhost mnt]# find /mnt -perm 404/mnt/file2##查看文件权限中u位有r权限,并且o位有r权限的文件[root@localhost mnt]# find /mnt -perm -404/mnt/mnt/file1/mnt/file2##查看文件权限中u位有r权限,或者o位有r权限的文件[root@localhost mnt]# find /mnt -perm /404/mnt/mnt/file1/mnt/file2/mnt/file3[root@localhost mnt]# ll -d /mnt/drwxr-xr-x. 2 root root 42 Nov 14 09:41 /mnt/
@7参数含义:ctime 与 cmin 都表示按照时间查找被篡改的文件ctime ##以天为单位cmin ##以分钟为单位 -cmin 10 #查找文件更新距离现在10分钟的文件-cmin +10 #查找文件更新距离现在超过10分钟的文件-cmin -10 #查找文件更新距离现在10分钟以内的文件-ctime +/-10 #查找文件更新距离现在超过10天/10天以内的文件
实验7:按文件更新的时间
[root@localhost ~]# cd /mnt[root@localhost mnt]# rm -rf *[root@localhost mnt]# ls##建立文件[root@localhost mnt]# touch file{1..3}##查找文件更新距离现在为1分钟的文件[root@localhost mnt]# find /mnt/ -ctime 1##查找文件更新距离现在为1分钟以内的文件[root@localhost mnt]# find /mnt/ -ctime -1/mnt//mnt/file1/mnt/file2/mnt/file3##查找文件更新距离现在超过1分钟的文件[root@localhost mnt]# find /mnt/ -ctime +1
参数含义:-exec 命令 {} \; #对查找到的文件执行某命令;-exec表示开始执行动作 {} 表示用find命令查找出的所有文件
实验8:对查找到的文件执行某些动作
(1).给/mnt下文件权限包含004的文件的g位加w的权限
[root@localhost mnt]# pwd/mnt[root@localhost mnt]# lltotal 0-rw-r--r-- 1 root root 0 Nov 14 10:06 file1-rw-r--r-- 1 root root 0 Nov 14 10:06 file2-rw-r--r-- 1 root root 0 Nov 14 10:06 file3##更改权限[root@localhost mnt]# chmod 404 /mnt/file2[root@localhost mnt]# lltotal 0-rw-r--r-- 1 root root 0 Nov 14 10:06 file1-r-----r-- 1 root root 0 Nov 14 10:06 file2-rw-r--r-- 1 root root 0 Nov 14 10:06 file3##给/mnt下文件权限包含004的文件的g位加w的权限[root@localhost mnt]# find /mnt -perm 404 -exec chmod g+w {} \;[root@localhost mnt]# lltotal 0-rw-r--r-- 1 root root 0 Nov 14 10:06 file1-r---w-r-- 1 root root 0 Nov 14 10:06 file2-rw-r--r-- 1 root root 0 Nov 14 10:06 file3
(2).将系统中属于mail组的文件备份到/mnt下
[root@localhost ~]# ll /mnttotal 0-rw-r--r-- 1 root root 0 Nov 14 10:06 file1-r---w-r-- 1 root root 0 Nov 14 10:06 file2-rw-r--r-- 1 root root 0 Nov 14 10:06 file3##将系统中属于mail组的文件备份到/mnt下[root@localhost ~]# find / -group mail -exec cp {} /mnt \;find: ‘/proc/6812/task/6812/fd/6’: No such file or directoryfind: ‘/proc/6812/task/6812/fdinfo/6’: No such file or directoryfind: ‘/proc/6812/fd/6’: No such file or directoryfind: ‘/proc/6812/fdinfo/6’: No such file or directorycp: omitting directory ‘/var/spool/mail’[root@localhost ~]# ll /mnttotal 0-rw-r--r-- 1 root root 0 Nov 14 10:06 file1-r---w-r-- 1 root root 0 Nov 14 10:06 file2-rw-r--r-- 1 root root 0 Nov 14 10:06 file3-rw-r----- 1 root root 0 Nov 14 10:14 rpc-rw-r----- 1 root root 0 Nov 14 10:14 student-rw-r----- 1 root root 0 Nov 14 10:14 westos
标签:
相关推荐:
最新新闻:
- 天天实时:CAP为什么没有明确考虑收敛性?分布式系统中的收敛性
- Unlocker解锁VMwareWorkstation虚拟机
- 什么是Oops?linux之Oops原理及解析|动态
- ExcelOOP函数怎么使用?Excel中VLOOKUP函数的详细用法
- find命令详解 linux下find命令的使用方法
- javascript_initialize构造函数 子类的构造函数|世界独家
- 用比特彗星如何下载?路由器端口映射教程
- 密锣紧鼓地开发年度盛典 BigoLive前端营收组同比更佳|当前热文
- 数组开小了、运行时间过长怎么办?解决方法 环球速看料
- 天天速讯:Java数组详解 java语言中使用数组的方法
- 《天外世界:太空人之选》现已在获准上市区域推出:全球快讯
- “健身猪”一只最高能卖8万元 食用口感不太好:每日视讯
- 世界即时看!厂商将为PS5推出"永不漂移"摇杆 可应用于精英手柄
- 《遗迹2》枪手介绍影片公开 发售日期待定-热资讯
- 天天消息!流行之王迈克尔杰克逊传记片在加州拍摄
- 虚幻5《最后生还者》粉丝恶搞视频 循声者搞笑聊天-全球最资讯
- 苹果推出黄色款iPhone14 3月14日开售 5999元起
- iPhone 15全系面板曝光:弧边实锤了
- 微信能用支付宝钱包了!:滚动
- 环球微速讯:iPhone新配色到来:科技以换壳为本
- 【环球报资讯】待机可达52天!内置10000mAh电池三防智能手机发布
- 全球速讯:恐怖生存新游《Hellspawn》上架steam 探索击溃邪教团
- 赛博朋克风ARPG《上行战场》全平台销量超100万份
- AMD显卡上线新促销:买RX 6000、RX 7000显卡送400元3A大作:每日快播
- 游戏越来越贵:去年英国游戏平均售价上涨近7%
- 世界观察:太空经营类游戏《火星地平线2:寻找生命之旅行》Steam页面上线 2024年发售
- 上海迪士尼和玲娜贝儿拥抱要排队6小时:互动一分钟 环球资讯
- 荃银高科:公司深耕水稻、玉米、小麦等主要农作物种子的研发、繁育、推广、服务及利用优质特色品种带动订单农业业务 焦点要闻
- 每日报道:云南白药年薪千万董事长离职 承诺半年内不转让股份
- 天天热讯:禁止恶俗烂梗!超20个"鸡你太美"商标被判无效
- 当前焦点!电影版《东京复仇者2》新剧照 前后篇4月6月上映
- T2正在进行裁员 声称对开发团队影响微乎其微:天天新要闻
- 胡克定律是什么
- 当前滚动:《人类:一败涂地》全球销量已超4000万套
- 全球快看点丨未成年强奸罪可判多少年
- 全球即时:《寂静岭2:重制版》新版护士形象公开身材火辣
- Take Two裁员 发行公司Private Division受波及
- 全球快播:立减205元 360°夜视摄像头仅需64元
- 美国特斯拉ModelS和X降价高达一万美元
- 13999!七彩虹RTX4090有货
- 【秒懂知识库】如何鉴别手机屏幕的好坏?
- 微软:Mac版Outlook免费
- 全球热资讯!《不要喂食猴子2099》5月25日登陆Steam 支持试玩
- 恐怖游戏《有一天你会归来:导演剪辑版》已推出|每日视讯
- PS及Switch美版《格林魔书 OnceMore》试玩版上架
- 物流金融:世界时讯
- PS5能用!2TB PCIe4固态跌破600!-世界观速讯
- 奥运健儿同款 喜德盛高端山地车127950元 当前热议
- 【秒懂知识库】选错用错损害健康 加湿器选购秘籍一般人不知道_环球速看料
- 办公神器 联想小新Pad仅需898元
- 绽放“她光彩” 三星显示器助力女性拥抱向上的力量|全球热文
- 多名韩国艺人整形医院就诊画面遭泄露:几乎没有天然脸
- 天天热文:燕王登基:《文明6》“永乐”成有史以来最受欢迎的文明领袖
- 英伟达531.18版驱动程序出现问题 退出游戏后CPU占用率可能会更高
- 父母嫌贵拒绝给买200多元的鞋子 28岁女子瞬间崩溃 环球快看
- 育碧回应业务重组:市场迫使我们转向线上服务游戏 天天播资讯
- 天天实时:《城市:天际线2》Xbox Series版成就泄露
- 花月正春风_花月满楼
- 38节特惠!小米Redmi note11t Pro跌至1499元_天天看点
- 威马汽车复活!将全力开展复工复产-资讯
- 一加Ace 2V发布:天玑9000处理器、2299元起
- 2299元起!一加Ace 2V发布来京东参与预售可享30天无忧试用
- 大国品牌帅丰集成灶刷屏机场+央视,引爆行业声势!|天天信息
- 热头条丨外媒:《王国之泪》游戏大小凸显了Switch的硬件限制
- 演员叶彤|全球今亮点
- 307元显卡挑战3050地位
- 新学期旗开得胜 三星Galaxy Tab S8系列带来高分秘籍-世界通讯
- 真彩女王 不被定义 罗技开启个性三八妇女节|速递
- 价格屠夫小米显示器369元_世界今热点
- 一加Ace 2V全球首发Wi-Fi技术:网络不卡了
- 热推荐:基地回应大熊猫福菀被游客泼水:目前大熊猫状态稳定 未查到泼水者
- 工地食堂成大学生新打卡点:13块随便吃 好吃还实惠_环球百事通
- Netflix动画《遗迹守护者》登陆TV 确定7月开播
- 迪士尼真人版《小美人鱼》女主新照 身材好很美丽
- 韩国出新制度:一周工作时间增至69小时 打工人喜迎996 当前热门