【无标题】find命令,exec,mtime,scp,crontab练习

  1. 使⽤ls查看/etc/⽬录下所有的⽂件信息

[root@localhost ~]# ls /etc/

  1. 2.使⽤ls查看/etc/⽬录下名包含“a”字⺟的⽂件或者⽬录信息

[root@localhost ~]# ls /etc/*a*

  1. 使⽤ls查看/etc/⽬录下以".conf"结尾的⽂件信息

[root@localhost ~]# ls /etc/*.conf

  1. 使⽤ls查看/etc/⽬录中以"y"字⺟开头的⽂件信息

[root@localhost ~]# ls /etc/y*

  1. find查找/var/⽬录中以“.log”⽂件

[root@localhost ~]# find /var/ -name "*.log" -type f

  1. 在opt⽬录下创建test⽬录

[root@localhost ~]# mkdir /opt/test

  1. 在test⽬录中创建abc.txt,def.txt.ghi.txt,xxx.txt.yyy.txt五个⽂件

[root@localhost ~]# touch /opt/test/abc.txt

[root@localhost ~]# touch /opt/test/def.txt

[root@localhost ~]# touch  /opt/test/ghi.txt

[root@localhost ~]# touch  /opt/test/xxx.txt

[root@localhost ~]# touch  /opt/test/yyy.txt

  1. 修改以上5个⽂件的最后修改时间分别为15,14,13,12,11,10⽇

[root@localhost ~]# touch /opt/test/abc.txt -m -d "2024-7-15 00:00"

[root@localhost ~]# touch /opt/test/def.txt -m -d "2024-7

-14 00:00"

[root@localhost ~]# touch /opt/test/ghi.txt -m -d "2024-7

-13 00:00"

[root@localhost ~]# touch /opt/test/xxx.txt -m -d "2024-7-12 00:00"

[root@localhost ~]# touch /opt/test/yyy.txt -m -d "2024-7-11 00:00"

  1. 在test⽬录下创建a⽬录

[root@localhost ~]# mkdir /opt/test/a

  1. 将以上5个⽂件复制⼀份到a⽬录中

 [root@localhost ~]# cp /opt/test/abc.txt /opt/test/a

[root@localhost ~]# cp /opt/test/def.txt /opt/test/a

[root@localhost ~]# cp /opt/test/ghi.txt /opt/test/a

[root@localhost ~]# cp /opt/test/xxx.txt /opt/test/a

[root@localhost ~]# cp /opt/test/yyy.txt /opt/test/a

  1. 将a⽬录⽂件做成bak.tar.gz⽂件保存到家⽬录中

[root@localhost ~]# tar -zcvf /root/bak.tar.gz -C /opt/test a/

  1. 使⽤find删除test⽬录下3天前的⽂件

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

  1.  find删除opt⽬录下3天内⽂件

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

  1. find删除正好第三天的⽂件

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

  1. 将/opt/test/a⽬录中的⽂件复制i⼀份到/opt/test/⽬录下

[root@diyi ~]# cp /opt/test/a/* /opt/test/

  1. 创建⽬录/opt/test0

[root@diyi ~]# mkdir /opt/test0

  1. 在/opt/test0/⽬录中创建三个⽂件 a.mp4(5M),b.mp4(20M),c.mp4(80M)

[root@diyi ~]# dd if=/dev/zero of=/opt/test0/a.mp4 bs=5M count=1

[root@diyi ~]# dd if=/dev/zero of=/opt/test0/b.mp4 bs=20M count=1

[root@diyi ~]# dd if=/dev/zero of=/opt/test0/c.mp4 bs=80M count=1

  1. 创建⽬录/opt/test0/b/

[root@diyi ~]# mkdir /opt/test0/b/

  1. 将/op t/test0/中的⽂件复制⼀份/opt/test0/b/⽬录中

[root@diyi ~]# cp /opt/test0/* /opt/test0/b/

  1. find查询/opt/test0/⽬录中⽂件⼤于20M的,并删除

 [root@diyi ~]# find /opt/test0/ -type f -size +20M -exec rm -rf {} \;

  1. find查询/opt/test0/⽬录中⽂件⼩于20M的⽂件并删除

 [root@diyi ~]# find /opt/test0/ -type f -size -20M -exec rm -rf {} \;

  1. find查找/opt/test0/⽬录中⽂件size为20M的⽂件并删除

[root@diyi ~]# find /opt/test0/ -type f -size 20M -exec rm -rf {} \;

  1. /opt/test0/b中的⽂件复制⼀份到/opt/test0中

[root@diyi ~]# cp /opt/test0/b/* /opt/test0

  1. 打开新的虚拟主机

25. 将家⽬录中的bak.tar.gz⽂件上传到新主机的/opt⽬录中

[root@diyi ~]# scp /root/bak.tar.gz root@192.168.2.12:/opt/

  1. 将新主机的/e tc/skel/⽬录下载到 当前主机的/opt⽬录中

[root@diyi ~]# scp -r root@192.168.2.12:/etc/skel/ /opt/

27. 设置计划任务,每周3将/e tc/yum.repos.d/⽬录下的.repo⽂件压缩保存到tmp,在⽂件

名中添加时间戳

[root@diyi ~]# crontab -e

* * * * */3 /usr/bin/tar -zcvf /tmp/etc_$(data "+\%Y\%M\%D\%H\%M\%S\").tar.gz /etc/yum.repos.d/*.repo

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值