第二周day01(find,tree,scp,计划任务):

find命令应用

1.find命令的通

主要进行文件搜索
2. 基本语法
find [ 文件路径 ] [ 选项 选项的值 ]
-name *
-type f|d
常见的选项
-name 根据文件的名称搜索文件,支持通配符 *
-type f 代表普通文件, d 代表目录
[root@localhost ~]# find /etc/ -name "*.conf" -type f

find 选项find /opt -name "*a*"

[root@localhost ~]# find /opt -name "*a*" -type f

 find -exec 对查找到的结果进行修改

[root@localhost ~]# find /opt/ -mtime +3 -exec rm -rf {} \;
 

清空opt目录下的所有文件 rm -rf /opt/*
创建1M 的文件 a.txt

创建b.txt 5M,c.txt 10M

2.stat命令

语法 touch -m -d 日期时间格式 文件名称
   60  touch /opt/c.txt -m -d "2024-7-11 00:00"
   61  touch /opt/d.txt -m -d "2024-7-12 00:00"
   62  touch /opt/e.txt -m -d "2024-7-13 00:00"
 
文件不存在就创建并修改时间
文件存在只配置最后修改时间

搜索时间

find 文件路径 -mtime +days/-days

-mtime 根据文件最后修改时间搜索文件
+ 号 搜索几天之前的文件信息
- 号 搜索几天之 的文件信息
   68  find /opt/ -mtime +3
   69  find /opt/ -mtime -3
 
删除的方法:
 76  find /opt/ -mtime +3 | xargs rm -rf
 80  find /opt/ -mtime +3 -exec rm -rf {} \;
 

根据文件size大小搜索文件

find 路径 -size 文件大小 [ 常用单位 k M G]
size 值 搜索等于 size 的文件
-size值 【 0 size )
+size 值 ( size 值,正无穷)
 

查找等于5M,大于5M,小于5M的文件

[root@localhost ~]# find /opt/ -size 5M
/opt/b.txt
[root@localhost ~]# find /opt/ -size +5M
/opt/c.txt
[root@localhost ~]# find /opt/ -size -5M
/opt/
/opt/a.txt

扩展命令 dd

使用dd创建扩展命令
生成指定大小的测试文件
语法   dd if=/dev/zero of=文件名称 bs=1M count=1
 
if 表示输入文件
of 表示输出文件
bs 代表字节为单位的块大小
count 代表被复制的块
其中 /dev/zore 是一个字符设备,会不断地返回 0 字节的文件

   92  dd if=/dev/zero of=/dpt/a.txt bs=1M count=1
   93  dd if=/dev/zero of=/opt/a.txt bs=1M count=1
   94  ls -lh /opt/
   95  dd if=/dev/zero of=/opt/b.txt bs=5M count=1
   96  dd if=/dev/zero of=/opt/c.txt bs=10M count=1
 

tree命令的使用

创建文件列表,将文件名称以树的形式展示

进行安装yum -y install tree

虚拟机的克隆

scp命令的使用

scp [ 选项 ] 用户名 @linux 主机地址 :/ 资源路径 linux 本地文件路径

下载 把数据从远程主机保存到本地主机

[root@localhost ~]# scp root@192.168.2.30:/opt/a.txt /opt
The authenticity of host '192.168.2.30 (192.168.2.30)' can't be established.
ECDSA key fingerprint is SHA256:SKAczJfI+wWGsyy5lXioA/cl02pIDN89EgxqCK99ow8.
ECDSA key fingerprint is MD5:0e:33:6b:5a:5d:53:9b:31:4a:7c:50:69:c6:03:85:ac.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.2.30' (ECDSA) to the list of known hosts.
root@192.168.2.30's password: 
a.txt                                        100% 1024KB  39.6MB/s   00:00    
[root@localhost ~]# ls /opt/
a.txt

[root@localhost ~]# mkdir /opt/d0
[root@localhost ~]# cp /opt/a.txt /opt/d0
[root@localhost ~]# [root@localhost ~]# cp /opt/b.txt /opt/d0
[root@localhost ~]# cp /opt/c.txt /opt/d0
远程主机查看

[root@localhost ~]# tree /opt/
/opt/
├── a.txt
├── b.txt
├── c.txt
└── d0
    ├── a.txt
    ├── b.txt
    └── c.txt

1 directory, 6 files
[root@localhost ~]# scp root@192.168.2.30:/opt/d0 /opt
root@192.168.2.30's password: 
scp: /opt/d0: not a regular file
[root@localhost ~]# scp -r   root@192.168.2.30:/opt/d0 /opt
root@192.168.2.30's password: 
a.txt                                        100% 1024KB  40.6MB/s   00:00    
b.txt                                        100% 5120KB  55.6MB/s   00:00    
c.txt                                        100%   10MB  57.4MB/s   00:00    

上传 把本地文件保存到远程主机

[root@localhost ~]# scp root@192.168.2.30:/opt/d0 /opt
root@192.168.2.30's password: 
scp: /opt/d0: not a regular file
[root@localhost ~]# scp -r   root@192.168.2.30:/opt/d0 /opt
root@192.168.2.30's password: 
a.txt                                        100% 1024KB  40.6MB/s   00:00    
b.txt                                        100% 5120KB  55.6MB/s   00:00    
c.txt                                        100%   10MB  57.4MB/s   00:00    
[root@localhost ~]# scp /opt/d0/a.txt  root@192.168.2.30:/opt/
root@192.168.2.30's password: 
a.txt                                        100% 1024KB  36.5MB/s   00:00    
[root@localhost ~]# scp -r /opt/d0/  root@192.168.2.30:/opt/
root@192.168.2.30's password: 
a.txt                                        100% 1024KB  26.7MB/s   00:00    
b.txt                                        100% 5120KB  50.6MB/s   00:00    
c.txt                                        100%   10MB  49.3MB/s   

查看是否存在计划任务

计划任务
crontab [ 选项 ]
-l list 查看当前用户的计划任务信息
-e edit 编写计划任务

[root@localhost ~]# crontab -l
每分钟自动将opt目录中的文件名写到

[root@localhost ~]# crontab -e
crontab: installing new crontab
[root@localhost ~]# crontab -l
*/1 * * * * /usr/bin/ls /opt/ >> /root/list
[root@localhost ~]# rm -rf /tmp/crontab
[root@localhost ~]# vim list
[root@localhost ~]# dd if=/dev/zero of=/opt/hhhhh.txt bs=100M count=1
记录了1+0 的读入
记录了1+0 的写出
104857600字节(105 MB)已复制,0.542155 秒,193 MB/秒

时间戳:

[root@localhost ~]# date "+%T"    输出时间
14:42:46
[root@localhost ~]# date "+%F"    输出年月日
2024-07-15
[root@localhost ~]# date "+%Y"    输出年
2024
[root@localhost ~]# date "+%m"     输出月
07
[root@localhost ~]# date "+%d"     输出日
15
[root@localhost ~]# date "+%Y%m%d"    输出年月日
20240715
[root@localhost ~]# date "+%Y%m%d%H%S"    输出年月日时分秒
202407151430

  • 27
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值