10 文件详细属性
知识点回顾
ls :命令
-l 详细
-a 隐藏
-d 查看目录本身
-r
-i inode号码
-t 文件创建时间
2.du 统计目录大小
[root@oldboyedu ~]
33M /etc/
3.inode号码
df -i
inode 号码或者磁盘空间任意一个满,都会导致磁盘无法写入
4.文件类型
- 普通文件 数据文件 压缩包 媒体文件
d 目录
b 块设备
l 软链接
c 字节文件 /dev/zero(生成指定大小的文件) /dev/null(黑洞设备)
s socket
5.同时接收正确和错误的结果定向到文件
echo oldboy > 1.txt 2> 2.txt
echo oldboy >>1.txt 2>&1
echo oldboy &>>1.txt
6.yum 安装
yum -y install 包名1 包2
yum -y remove 包名
yum repolist
yum clean all
yum reinstall
yum -y localinstall
[root@oldboyedu ~]
7.rpm 安装
rpm -qa |grep wget
rpm -qa wget
rpm -ivh 安装包(xxx.rpm)
rpm -e wget
rpm -ql wget
文件详细属性
01.find查找文件
语法结构:
find 在哪里查找 按照什么类型查找
注意:find默认递归查找文件
案例1:按照文件的类型查找
f 普通文件 -
d 目录
l 软链接
c 字节设备
b 块设备
语法结构: find ./ -type 文件类型
[root@db01 ~]
[root@db01 ~]
[root@db01 oldboy]
[root@db01 oldboy]
[root@db01 oldboy]
[root@db01 oldboy]
total 0
-rw-r--r-- 1 root root 0 Mar 13 09:29 1.log
-rw-r--r-- 1 root root 0 Mar 13 09:29 1.txt
-rw-r--r-- 1 root root 0 Mar 13 09:29 1.TXT
-rw-r--r-- 1 root root 0 Mar 13 09:29 2.log
-rw-r--r-- 1 root root 0 Mar 13 09:29 2.txt
-rw-r--r-- 1 root root 0 Mar 13 09:29 2.TXT
-rw-r--r-- 1 root root 0 Mar 13 09:29 3.log
-rw-r--r-- 1 root root 0 Mar 13 09:29 3.txt
-rw-r--r-- 1 root root 0 Mar 13 09:29 3.TXT
[root@db01 oldboy]
[root@db01 oldboy]
total 0
-rw-r--r-- 1 root root 0 Mar 13 09:29 1.log
-rw-r--r-- 1 root root 0 Mar 13 09:29 1.txt
-rw-r--r-- 1 root root 0 Mar 13 09:29 1.TXT
-rw-r--r-- 1 root root 0 Mar 13 09:29 2.log
-rw-r--r-- 1 root root 0 Mar 13 09:29 2.txt
-rw-r--r-- 1 root root 0 Mar 13 09:29 2.TXT
-rw-r--r-- 1 root root 0 Mar 13 09:29 3.log
-rw-r--r-- 1 root root 0 Mar 13 09:29 3.txt
-rw-r--r-- 1 root root 0 Mar 13 09:29 3.TXT
drwxr-xr-x 2 root root 6 Mar 13 09:30 oldboy-1
drwxr-xr-x 2 root root 6 Mar 13 09:30 oldboy-2
drwxr-xr-x 2 root root 6 Mar 13 09:30 oldboy-3
drwxr-xr-x 2 root root 6 Mar 13 09:30 oldboy-4
按照深度等级查找文件:
案例:只查找1级目录下的文件
[root@oldboyedu oldboy]
./1.txt
./2.txt
./3.txt
./1.log
./2.log
./3.log
案例1:查找当前目录下所有的普通文件
[root@oldboyedu oldboy]
./1.txt
./2.txt
./3.txt
./1.log
./2.log
./3.log
./1.TXT
案例2:查找当前目录下所有的目录
[root@oldboyedu oldboy]
./
./oldboy-1
./oldboy-2
./oldboy-3
./oldboy-4
案例3:按照文件的名称查找
语法: find ./ -name "文件名称/目录名称"
[root@oldboyedu oldboy]
./1.txt
案例4:按照文件的名称模糊查找
[root@oldboyedu oldboy]
./1.txt
./2.txt
./3.txt
./2008-1.txt
./2008-2.txt
./2008-3.txt
./2008-4.txt
./2008-5.txt
./s.txt
./all.txt
./22.txt
案例5:按照文件名称查找忽略大小写
[root@oldboyedu oldboy]
./1.txt
./2.txt
./3.txt
./1.TXT
./2.TXT
./3.TXT
./4.TXT
案例6.按照文件的目录名查找
[root@oldboyedu oldboy]
./oldboy-1
案例7:按照文件的inode号码查找
[root@oldboyedu oldboy]
./2.log
案例8:按照类型和名称联合查找
[root@oldboyedu oldboy]
./1.txt
案例9:find按照大小查找
语法: find ./ -size 10M
+10M
-10M
案例:创建实验环境
[root@db01 oldboy]
[root@db01 oldboy]
33528 s.txt
[root@db01 oldboy]
11176 /etc/services
[root@db01 oldboy]
-rw-r--r-- 1 root root 2.0M Mar 13 10:06 s.txt
[root@db01 oldboy]
[root@db01 oldboy]
-rw-r--r-- 1 root root 16M Mar 13 10:07 all.txt
[root@db01 oldboy]
案例1:查找等于10M的文件
[root@oldboyedu oldboy]
./test.log
案例2:查找大于10M的文件
[root@oldboyedu oldboy]
./all.txt
./22.txt
案例3:查找小于10M的文件
[root@oldboyedu oldboy]
./
./1.txt
./2.txt
./3.txt
./1.log
./2.log
./3.log
./oldboy-1
./oldboy-2
./oldboy-3
./oldboy-4
./1.TXT
./2.TXT
./3.TXT
./4.TXT
案例4:查找普通文件大于10M的
[root@oldboyedu oldboy]
./all.txt
./22.txt
案例5:查找文件大于5M并且小于15M的文件
find命令默认参数之间是且的关系
并且:and 同时成立
或者: or 成立一个即可
[root@oldboyedu oldboy]
案例6:查找文件等于10M或者文件大于15M的文件
[root@oldboyedu oldboy]
./test.log
案例:查找文件名.txt 并且大于5M的文件
[root@oldboyedu oldboy]
./all.txt
./22.txt
案例7:find按照时间查找
-mtime
find ./ -mtime 7
+7
-7
第一步:实验环境
[root@oldboyedu oldboy]
Fri Oct 10 00:00:00 CST 2008
[root@oldboyedu oldboy]
[root@oldboyedu oldboy]
total 0
-rw-r--r-- 1 root root 0 Mar 13 2024 1.log
-rw-r--r-- 1 root root 0 Mar 13 2024 1.txt
-rw-r--r-- 1 root root 0 Mar 13 2024 1.TXT
-rw-r--r-- 1 root root 0 Oct 10 00:00 2008-1.txt
-rw-r--r-- 1 root root 0 Oct 10 00:00 2008-2.txt
-rw-r--r-- 1 root root 0 Oct 10 00:00 2008-3.txt
-rw-r--r-- 1 root root 0 Oct 10 00:00 2008-4.txt
-rw-r--r-- 1 root root 0 Oct 10 00:00 2008-5.txt
-rw-r--r-- 1 root root 0 Mar 13 2024 2.log
-rw-r--r-- 1 root root 0 Mar 13 2024 2.txt
-rw-r--r-- 1 root root 0 Mar 13 2024 2.TXT
-rw-r--r-- 1 root root 0 Mar 13 2024 3.log
[root@oldboyedu oldboy]
[root@oldboyedu oldboy]
案例1:查找7天前的文件,企业中数据备份
[root@oldboyedu oldboy]
./2008-1.txt
./2008-2.txt
./2008-3.txt
./2008-4.txt
./2008-5.txt
案例2:查找修改时间小于7天(7天内的)的文件。系统中毒被黑客攻击,文件篡改
[root@oldboyedu oldboy]
./1.txt
./2.txt
./3.txt
./1.log
./2.log
./3.log
./1.TXT
./2.TXT
./3.TXT
./4.TXT
案例3:按照类型和名称联合查找
[root@oldboyedu oldboy]
./1.txt
面试题:查找oldboy目录7天前的文件并删除
[root@oldboyedu oldboy]
find查找到的结果交给其他命令
方法1:
1.find命令结果交给rm 命令
xargs将find查找到的结果甩到命令的最后面
xargs后面的别名失效
语法: find ./ -type f |xargs rm
案例:查找.TXT文件后删除
[root@oldboyedu oldboy]
案例1:删除目录需要-r
[root@oldboyedu oldboy]
案例2:将find的执行结果交给ls 查看详细信息
[root@oldboyedu oldboy]
-rw-r--r-- 1 root root 0 Mar 13 09:29 ./1.txt
案例3:查找的文件交给cat查看
[root@oldboyedu oldboy]
[root@oldboyedu oldboy]
./2008-1.txt
./2008-2.txt
[root@oldboyedu oldboy]
aaaaa
bbbbb
[root@oldboyedu oldboy]
./2008-33.txt
[root@oldboyedu oldboy]
案例4:find结果交给cp
[root@oldboyedu oldboy]
[root@oldboyedu oldboy]
total 15360
-rw-r--r-- 1 root root 15728640 Mar 13 18:15 all.txt
案例5:find结果交给mv
[root@oldboyedu oldboy]
[root@oldboyedu oldboy]
-rw-r--r-- 1 root root 15728640 Mar 13 15:55 /opt/all.txt
案例6:find结果交给
小结:
find ./ -type f |xargs rm
find ./ -type f |xargs cat
find ./ -type f |xargs ls -l
find ./ -name "a.txt" |xargs -i cp {} /opt
find ./ -name "a.txt" |xargs -i mv {} /opt
案例1:将find的结果交给 rm
find ./ -name "2008-1.txt" -exec rm {} \;
案例2:将find的结果交给 ls
find ./ -name "2008-2.txt" -exec ls {} \;
案例3:将find的结果交给 cp mv
[root@oldboyedu oldboy]
[root@oldboyedu oldboy]
total 4
-rw-r--r-- 1 root root 6 Mar 13 20:19 2008-2.txt
[root@oldboyedu oldboy]
[root@oldboyedu oldboy]
total 39860
-rw-r--r-- 1 root root 0 Mar 13 20:22 1.log
-rw-r--r-- 1 root root 0 Mar 13 20:22 1.txt
-rw-r--r-- 1 root root 6 Mar 13 20:22 2008-1.txt
-rw-r--r-- 1 root root 6 Mar 13 20:22 2008-2.txt
-rw-r--r-- 1 root root 0 Mar 13 20:22 2008-333.txt
方法三:使用``先执行``里边的内容或者使用$()先执行()里边的内容
把find的结果交给rm cp ls mv
案例1:把find的结果交给rm
rm -rf `find ./ -name "all.txt"`
rm -rf $(find ./ -name "all.txt)
案例2:把find的结果交给cp
cp `find ./ -name "all.txt"` /tmp/
cp $(find ./ -name "all.txt") /tmp
案例3:把find的结果交给ls
ls -l `find ./ -type f -name "all.txt"`
ll $(find ./ -type f -name "all.txt")
小结-exec
find ./ -name "1.txt" -exec rm {} \;
find ./ -type f -exec cp {} /opt \;
find ./ -type f -exec mv {} /tmp/ \;
Linux命令行中具有特殊意义的符号
&& `作用:前面的命令必须执行成功之后才执行后面的命令 。短路与`
|| `作用:前面的命令必须执行失败之后才能执行后面的命令`
; `作用:命令连接符号`
&& 案例:前面的命令执行成功,才执行后面的命令
[root@oldboyedu oldboy]
hehe
[root@oldboyedu oldboy]
-bash: ech: command not found
[root@oldboyedu oldboy]
-bash: eho: command not found
[root@oldboyedu oldboy]
ls: cannot access 111111.txt: No such file or directory
|| 案例:前面的
[root@oldboyedu data]
-bash: cd: /data/: No such file or directory
[root@oldboyedu data]
[root@oldboyedu data]
-bash: cd: /data/: No such file or directory
[root@oldboyedu data]
total 0
[root@oldboyedu data]
[root@oldboyedu data]
[root@oldboyedu data]
total 0
; 案例:命令连接符,不管前面的命令执行成功还是失败都执行后面的
[root@oldboyedu data]
hehe
-bash: ech: command not found
[root@oldboyedu data]
-rw-r--r-- 1 root root 0 Mar 13 20:17 111.txt
[root@oldboyedu data]
-bash: ech: command not found
-bash: tuo: command not found
-bash: ehc: command not found
知识点小结:
find 查找文件
find ./ -name ""
find ./ -iname ""
find ./ -inum ""
find ./ -type f d c
find ./ -type f -name ""
find ./ -maxdepth 1 -type f
find ./ -size -10M -or +10M
find ./ -size 10M -size +15M
find ./ -size 10M -or -name "1.txt"
find ./ -mtime +7 -7
find ./ -name "1.txt" |xargs rm -r
find ./ -name "1.txt" |xargs ls -l
find ./ -name "1.txt" |xargs -i cp -r {} /opt
find ./ -name "1.txt" -exec rm {} \;
find ./ -name "1.txt" -exec ls -l {} \;
find ./ -name "1.txt" -exec cp {} /opt \;
rm -rf `find ./ -name "1.txt"`
ll `find ./ -name "1.txt"`
cp -rf `find ./ -name "1.txt"`
rm -rf $(find ./ -name "1.txt")
ll $(find ./ -name "1.txt")
cp $(find ./ -name "1.txt") /opt
特殊符号:
&& :前面的命令必须执行成功后面的命令才执行
|| :前面的命令必须执行失败后面的命令才执行
; : 作用命令连接符号
du -sh 文件/目录