1.find--主要进行文件搜索
基本用法:find [文件路径] [选项 选项的值]
-name *
-type f|d
常见的选项
-name 根据文件的名称搜索文件,支持通配符*
-type代表普通文件,d代表目录
*通配符
在Linux系统中,如果要查找的文件的名称不清晰,可以使用部分文件名+* 搜索
案列 获取/etx/中以.conf结尾的文件
.........
案例 搜索以httpd开头的文件
........
2.创建文件并设置文件的最后修改的时间
文件的时间的概念
(1).创建时间
(2).修改时间
(3).访问时间
使用stat命令获取文件的时间信息
语法stat文件
案列创建文件,并配置文件的修改时间
语法 touch -m -d 日期时间格式 文件名称
文件不存在就创建并修改时间
文件存在只配置 最后修改时间
[root@localhost ~]# touch /opt/def.txt //创建文件
[root@localhost ~]# stat /opt/def.txt //查看文件信息
文件:"/opt/def.txt"
大小:0 块:0 IO 块:4096 普通空文件
设备:fd00h/64768d Inode:33843175 硬链接:1
权限:(0644/-rw-r--r--) Uid:( 0/ root) Gid:( 0/ root)
环境:unconfined_u:object_r:usr_t:s0
最近访问:2024-07-15 23:56:24.985986799 +0800
最近更改:2024-07-15 23:56:24.985986799 +0800
最近改动:2024-07-15 23:56:24.985986799 +0800
创建时间:-
[root@localhost ~]# touch -m -d "2024-7-15 00:00" /opt/def.txt //设置最后修改时间为2024-7.15
[root@localhost ~]# stat /opt/def.txt //查看文件信息
文件:"/opt/def.txt"
大小:0 块:0 IO 块:4096 普通空文件
设备:fd00h/64768d Inode:33843175 硬链接:1
权限:(0644/-rw-r--r--) Uid:( 0/ root) Gid:( 0/ root)
环境:unconfined_u:object_r:usr_t:s0
最近访问:2024-07-15 23:56:24.985986799 +0800
最近更改:2024-07-15 00:00:00.000000000 +0800
最近改动:2024-07-15 23:57:35.050988746 +0800
创建时间:-
创建第三个文件
[root@localhost ~]# touch /opt/ghi.txt -m -d "2024-7-14 00:00"
[root@localhost ~]# stat /opt/ghi.txt
文件:"/opt/ghi.txt"
大小:0 块:0 IO 块:4096 普通空文件
设备:fd00h/64768d Inode:33843178 硬链接:1
权限:(0644/-rw-r--r--) Uid:( 0/ root) Gid:( 0/ root)
环境:unconfined_u:object_r:usr_t:s0
最近访问:2024-07-16 00:01:07.318994645 +0800
最近更改:2024-07-14 00:00:00.000000000 +0800
最近改动:2024-07-16 00:01:07.318994645 +0800
创建时间:-
查看文件
[root@localhost ~]# ls -l /opt/*.txt
-rw-r--r--. 1 root root 1048576 7月 15 19:00 /opt/a.txt
-rw-r--r--. 1 root root 0 7月 15 00:00 /opt/def.txt
-rw-r--r--. 1 root root 0 7月 14 00:00 /opt/ghi.txt
3.根据文件最后修改时间搜索文件
语法: find 文件路径 -mtime +days/-days
-mtime根据文件最后修改时间搜索文件
+号 搜索几天之前的文件信息
-号 搜索几天之内的文件信息
案列 搜索3天以前的信息。不包含第三个的,而且只搜txt文件
[root@localhost ~]# touch /opt/b.txt -m -d "2024-7-11 00:00"
[root@localhost ~]# touch /opt/c.txt -m -d "2024-7-10 00:00"
[root@localhost ~]# touch /opt/d.txt -m -d "2024-7-9 00:00"
[root@localhost ~]# touch /opt/e.txt -m -d "2024-7-8 00:00"
[root@localhost ~]# ls -l /opt/*.txt
-rwxr-xr-x. 1 root root 1048576 7月 15 19:09 /opt/a.txt
-rw-r--r--. 1 root root 0 7月 11 00:00 /opt/b.txt
-rw-r--r--. 1 root root 0 7月 10 00:00 /opt/c.txt
-rw-r--r--. 1 root root 0 7月 9 00:00 /opt/d.txt
-rw-r--r--. 1 root root 0 7月 8 00:00 /opt/e.txt
[root@localhost ~]# find /opt/e.txt -name "*.txt" -mtime +3
搜索三天以内的文件 .txt,包含今天
find /opt/a.txt -name "*.txt" -mtime -3
4.find的exec选项
案列 删除系统/var/log/ 10天之前的日志
方法1:使用xargs将查询结果交给rm ,可行
[root@localhost ~]# find /opt/ -name "*.txt" -type f -mtime +3|xargs rm -rf
方法2:使用find 执行-exec
语法:find 文件路径
5.用于快速生成指定大小的文件
根据文件size大小搜索文件
find 路径 -size 文件大小[常用单位 KMG]
size值 搜索等于size的文件
-size值【0,size值)
+size值 (size值,正无穷)
扩展命令dd
使用dd创建扩展命令
生成指定大小的测试文件
语法:dd if=/dev/zero of=文件名称 bs=1M count=1
if 表示输入文件 of 表示输出文件 bs 代表字节为单位的块大小 count 代表被复制的块
其中/dev/zero是一个字符设备。会不断地返回0字节文件
案列 创建一个1M的文件
生成其他大小的文件
6.根据文件大小搜所文件
基本语法
find 文件路径 -size size值 (单位KMG)
size值 搜索等于size大小的文件
-size值 [0,size值)
+size值 (size值,无穷大)
案列 搜索系统大于100妈的文件
删除root目录下文件大于100M的文件
7.tree指令
创建文件列表,将文件名称以树的形式展示
需要yum指令进行安装
yum -y install tree
案列:以树状结构显示/var/log 目录中的文件
8.scp
scp要求两台主机的系统都是linux系统
1.使用scp下载文件和目录
语法:scp [选项] 用户名@linux主机地址:/资源路径 linux本地文件路径
复制文件
1.查看克隆机的ip地址,并且清空opt目录中的文件
ifconfig
rm -rf /opt/*
2.查看原主机的ip地址,并且查看opt目录中的数据
ifconfig
ls -l /opt/
3.从原主机上下载/opt/a.txt到克隆机上的/opt目录,注意如果有询问,输入yes
scp /opt/a.txt root@192.168.2.9:/root
再输入密码即可
复制目录
1.源主机opt目录下创建目录,并且将a.txt b.txt c.txt复制一份在新目录中
tree /opt/
2.在克隆机上上使用scp指令复制到本地opt目录,需要添加-r选项,无法执行
第二次连接主机,不需要输入yes
-r代表递归,主要作用于文件夹
9.scp上传文件
![](https://i-blog.csdnimg.cn/direct/edcebc3240a748098f40f3f18fb9c2e2.png)
![](https://i-blog.csdnimg.cn/direct/2e9b4c54bde74bd9bf5de52c087ab14d.png)
![](https://i-blog.csdnimg.cn/direct/8b52c7e276824188a5971aee506c540c.png)
![](https://i-blog.csdnimg.cn/direct/249b0b9190884cb7b251f292022c3707.png)
![](https://i-blog.csdnimg.cn/direct/9293de13075d439eafeff119c97ef9db.png)
![](https://i-blog.csdnimg.cn/direct/8408bf0ebdfc46c69e269bedbf356301.png)
![](https://i-blog.csdnimg.cn/direct/c2e4e95542244c58877f1ed9508aca9f.png)
![](https://i-blog.csdnimg.cn/direct/25cec9cbd5e847649e993971a9ce0028.png)
![](https://i-blog.csdnimg.cn/direct/5d33b151a67d477a992b9b933bc4954c.png)
![](https://i-blog.csdnimg.cn/direct/0cceafa68d09413189b9d21fef2deb9e.png)
![](https://i-blog.csdnimg.cn/direct/c6748e4e990d4fb59855f3abc54c8e2b.png)