day6.5

day6.5

文件查找

# tee 
'可以从标准输入设备读取数据,将其内容输出到标准输出设备,同时还能保存成文件'

# xargs
'处理数据流,有些命令没有标准输入可以使用xargs'
# 文件查找命令
find [路径] [选项] [表达式] [动作]

按文件类型查找

# 选项
-type:
f:可编辑文件
d:目录
l:软连接文件
b:块设备文件 (磁盘,u盘)
c:字符设备文件
s:安全套接字文件
p:管道文件
# 举例
查找出文件详细信息
find /run -type s|xargs ls

按文件大小查找

# -size
-:小于
+:大于
# 举例
查找tmp下小于1M的文件
[root@28technicians ~]# find /tmp/ -size -1M|xargs ls -l
-rw-r--r--. 1 root root 0 Apr 14 18:22 /tmp/file1
-rw-r--r--. 1 root root 0 Apr 14 18:22 /tmp/file10

按文件名查找

# -name
'严格区分大小写'
# 举例
查找etc目录下的cjk文件
[root@28technicians ~]# find /etc/ -name 'cjk'
/etc/sudoers.d/tmp/cjk
/etc/sudoers.d/tmp/cjk/cjk
# -iname
'不区分大小写'
# 选项
查找etc目录下的cjk文件
[root@28technicians ~]# find / -name 'CJK'
/etc/sudoers.d/tmp/cjk
/etc/sudoers.d/tmp/cjk/cjk

按照文件时间查找

# 一个文件下有三种时间
-atime:文件访问时间查找
-mtime:文件内容创建,修改时间查找
-ctime:文件属性,修改时间查找
# 举例
查看root下近7天的文件(从今天开始算起)
[root@28technicians ~]# find /root ! -mtime -7
/root/.bash_logout
/root/.bash_profile
/root/.bashrc
/root/.cshrc
/root/.tcshrc
/root/anaconda-ks.cfg
/root/1.txt/passwd
/root/passwd
/root/.vimrc
/root/2.txt
/root/.2.txt.swp
/root/6666.txt
/root/000.txt

按照文件用户和组查找

# -user:查找文件的属主
-nouser:文件没有属主的用户
-group:查找文件的属组
-nogroup:文件没有属组的用户
# 举例
查看属主是wc的文件
[root@28technicians ~]# find /root -user 'wc'|xargs ls -l
-rw-r--r--. 1 wc wc2 61 Apr 14 08:23 /root/cjk.txt

查看属组是wc2的文件
[root@28technicians ~]# find /root -group 'wc2'|xargs ls -l
-rw-r--r--. 1 wc wc2 61 Apr 14 08:23 /root/cjk.txt

按照文件权限查找

# -perm
# 举例
精确查找
[root@28technicians ~]# find /root -perm 644|xargs ls -l
-rw-r--r--. 1 root root   133 Apr  6 14:15 /root/000.txt
-rw-r--r--. 1 root root   798 Mar 31 09:44 /root/1.txt/passwd

每个权限位上,都要包含该数字权限的所有权限
[root@28technicians ~]# find /root -perm -600|xargs ls -l
-rw-r--r--. 1 root root   133 Apr  6 14:15 /root/000.txt
-rw-r--r--. 1 root root   798 Mar 31 09:44 /root/1.txt/passwd

总共三个权限位,只要一个权限位被包含,就可以找到
[root@28technicians ~]# find /root -perm /644|xargs ls -l
-rw-r--r--. 1 root root   133 Apr  6 14:15 /root/000.txt
-r-x-w-r--. 1 root root    97 Apr  5 15:51 /root/6666.txt

按深度查找

# -maxdepth
'针对目录层级查找'
# 举例
查找/etc目录下的所有一级和二级目录
[root@28technicians ~]# find /etc/ -type d -maxdepth 2
/etc/
/etc/grub.d

find动作(了解)

名称 作用
-print 打印查找的内容到终端上(find命令默认就是打印)
-ls 查看文件详细信息
-deltet 删除查找文件
-ok 找到文件后,执行后面的bash命令,询问是否要操作

find多条件

-a:和,并且(默认)
-o:或者
!:取反
posted @   Gabydawei  阅读(18)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
点击右上角即可分享
微信分享提示