Linux的文件查找吉计划任务练习题

#练习1   使用ls查看/etc/目录下的所有文件信息
[root@gym ~]# ls /etc/

#练习2   使用ls查看/etc/⽬录下名包含“a”字⺟的⽂件或者⽬录信息
[root@gym ~]# ls /etc/ | grep 'a'

#练习3   使用ls查看/etc/目录下以“.conf”结尾的文件信息
[root@gym ~]# ls /etc/*.conf

#练习4   使用ls查看/etc/目录中以“y”字母开头的文件信息
[root@gym ~]# ls /etc/y*

#练习5   find查找/var/目录中以“.log”文件
[root@gym ~]# find /var/ -name "*.log" -type f

#练习6   在opt目录下创建test目录
[root@gym ~]# mkdir /opt/test

#练习7   在test目录中创建abc.txt,def.txt,ghi.txt,xxx.txt,yyy.txt五个文件
[root@gym ~]# touch /opt/test/abc.txt
[root@gym ~]# touch /opt/test/def.txt
[root@gym ~]# touch /opt/test/ghi.txt
[root@gym ~]# touch /opt/test/xxx.txt
[root@gym ~]# touch /opt/test/yyy.txt

#练习8   修改以上5个文件的最后修改时间分别为15,14,13,12,11,10日
[root@gym ~]# touch /opt/test/abc.txt -m -d "2024-7-15"
[root@gym ~]# touch /opt/test/def.txt -m -d "2024-7-14"
[root@gym ~]# touch /opt/test/ghi.txt -m -d "2024-7-13"
[root@gym ~]# touch /opt/test/xxx.txt -m -d "2024-7-12"
[root@gym ~]# touch /opt/test/yyy.txt -m -d "2024-7-11"

#练习9   在test目录下创建a目录
[root@gym ~]# mkdir /opt/test/a

#练习10   将以上5个文件复制一份到a目录中
[root@gym ~]# cp /opt/test/*txt /opt/test/a

#练习11   将a目录文件做成bak.tar.gz文件保存到家目录中
[root@gym ~]# tar -zcvf /home/bak.tar.gz /opt/test/a

#练习12   使用find删除test目录下3天前的文件
[root@gym ~]# find /opt/test -mtime +3 |xargs rm -rf

#练习13   find 删除opt目录下3天内的文件
[root@gym ~]# find /opt -mtime -3 -exec rm -rf {} \;

#练习14   find删除正好第三天的文件
[root@gym ~]# find /opt -mtime 3 -exec rm -rf {} \;

#练习15   将/opt/test/a目录中的文件复制一份到/opt/test/目录下
[root@gym ~]# cp /opt/test/a/* /opt/test/

#练习16   创建目录/opt/test0
[root@gym ~]# mkdir /opt/test0

#练习17   在/opt/test0/目录中创建三个文件 a.mp4(5M),b.mp4(20M),c.mp4(80M)
[root@gym ~]# dd if=/dev/zero of=/opt/test0/a.mp4 bs=1M count=5
[root@gym ~]# dd if=/dev/zero of=/opt/test0/b.mp4 bs=1M count=20
[root@gym ~]# dd if=/dev/zero of=/opt/test0/c.mp4 bs=1M count=80

#练习18   创建目录/opt/test0/b/
[root@gym ~]# mkdir /opt/test0/b/

#练习19   将/opt/test0/中的文件复制一份到/opt/test0/b目录中
[root@gym ~]# cp /opt/test0/ /opt/test0/b/

#练习20   find查询/opt/test0/目录中文件大于20M的,并删除
[root@gym ~]# find /opt/test0/ -type f -size +20M -exec rm -rf {} \;

#练习21   find查询/opt/test0/目录中文件小于20M的,并删除
[root@gym ~]# find /opt/test0/ -size -20M -type f -exec rm -rf {} \;

#练习22   find查询/opt/test0/目录中文件为20M的,并删除
[root@gym ~]# find /opt/test0/ -size 20M -type f -exec rm -rf {} \;

#练习23   /opt/test0/b中的文件复制一份到/opt/test0目录中
[root@gym ~]# cp /opt/test0/b/ /opt/test0/

#练习24   打开新的虚拟主机
打开vm,克隆一台主机并打开

#练习25   将家目录中的bak.tar.gz文件上传到新主机的/opt目录中
[root@gym ~]# scp /home/bak.tar.gz root@192.168.5.4:/opt/
root@192.168.5.4's password: 
bak.tar.gz                                                                                     100%  181   207.6KB/s   00:00    
新主机:
[root@localhost ~]# ls /opt/
bak.tar.gz

#练习26   将新主机的/etc/skel/目录下载到当前主机的/opt目录中
[root@gym ~]# scp -r root@192.168.5.4:/etc/skel /opt
root@192.168.5.4's password: 
.bash_logout                                                                                   100%   18     9.9KB/s   00:00    
.bash_profile                                                                                  100%  193   133.1KB/s   00:00    
.bashrc                                                                                        100%  231   358.4KB/s   00:00    
[root@gym ~]# ls /opt/
skel  test  test0

#练习27   设置计划任务,每周3将/etc/yum.repos.d/目录下的.repo文件压缩保存到tmp,在文件命中添加时间戳
[root@gym ~]# crontab -e
0 0 * * 3 tar -cvzf /tmp/yum.repos.d_$(date "+\%Y\%m\%d\%H\%M\%S").tar.gz /etc/yum.repos.d/*.repo
[root@gym ~]# crontab -l
 

  • 8
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值