对ls,通配符*,find,touch,mkdir,scp,计划任务crontab的练习

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


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

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


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


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


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

[root@xm ~]# mkdir /opt/test
[root@xm ~]# ls /opt
test

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

[root@xm ~]# cd /opt/test
[root@xm test]# touch  abc.txt def.txt  ghi.txt xxx.txt  yyy.txt
[root@xm test]# ls
abc.txt  def.txt  ghi.txt  xxx.txt  yyy.txt
 


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

[root@xm test]# touch -m -d "2024-7-14 00:00" abc.txt
[root@xm test]# touch -m -d "2024-7-13 00:00" def.txt
[root@xm test]# touch -m -d "2024-7-12 00:00" ghi.txt
[root@xm test]# touch -m -d "2024-7-11 00:00" xxx.txt
[root@xm test]# touch -m -d "2024-7-10 00:00" yyy.txt
[root@xm test]# ls -l
总用量 0
-rw-r--r--. 1 root root 0 7月  14 00:00 abc.txt
-rw-r--r--. 1 root root 0 7月  13 00:00 def.txt
-rw-r--r--. 1 root root 0 7月  12 00:00 ghi.txt
-rw-r--r--. 1 root root 0 7月  11 00:00 xxx.txt
-rw-r--r--. 1 root root 0 7月  10 00:00 yyy.txt
 


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

[root@xm test]# mkdir a
[root@xm test]# ls
a  abc.txt  def.txt  ghi.txt  xxx.txt  yyy.txt

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

[root@xm test]# cp -p  *.txt  a
[root@xm test]# ls a
abc.txt  def.txt  ghi.txt  xxx.txt  yyy.txt

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

[root@xm test]# tar -zcvf /home/bak.tar.gz  a
a/
a/abc.txt
a/def.txt
a/ghi.txt
a/xxx.txt
a/yyy.txt
[root@xm test]# ls /home
bak.tar.gz  user1  user2

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

[root@xm test]# find /opt/test -mtime +3  | xargs rm -rf
[root@xm test]# ls  -l /opt/test
总用量 0
drwxr-xr-x. 2 root root 51 7月  15 17:00 a
-rw-r--r--. 1 root root  0 7月  14 00:00 abc.txt
-rw-r--r--. 1 root root  0 7月  13 00:00 def.txt
-rw-r--r--. 1 root root  0 7月  12 00:00 ghi.txt

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

[root@xm test]# find /opt/ -mtime -3  | xargs rm -rf


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

[root@xm test]# find /opt/test -mtime 3  | xargs rm -rf

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

[root@xm test]# cp -p /opt/test/a  /opt/test


16. 创建⽬录/opt/test0

[root@xm ~]# mkdir /opt/test0
[root@xm ~]# ls /opt
test  test0

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

[root@xm ~]# cd /opt/test0
[root@xm test0]# dd if=/dev/zero of=a.mp4 bs=5M count=1
记录了1+0 的读入
记录了1+0 的写出
5242880字节(5.2 MB)已复制,0.0156014 秒,336 MB/秒
[root@xm test0]# dd if=/dev/zero of=b.mp4 bs=20M count=1
记录了1+0 的读入
记录了1+0 的写出
20971520字节(21 MB)已复制,0.0564595 秒,371 MB/秒
[root@xm test0]# dd if=/dev/zero of=c.mp4 bs=80M count=1
记录了1+0 的读入
记录了1+0 的写出
83886080字节(84 MB)已复制,0.274204 秒,306 MB/秒
[root@xm test0]# ls -l
总用量 107520
-rw-r--r--. 1 root root  5242880 7月  15 17:41 a.mp4
-rw-r--r--. 1 root root 20971520 7月  15 17:41 b.mp4
-rw-r--r--. 1 root root 83886080 7月  15 17:41 c.mp4
 


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

[root@xm test0]# mkdir b/
[root@xm test0]# ls
a.mp4  b  b.mp4  c.mp4

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

[root@xm test0]# cp *  b/

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

[root@xm test0]# find /opt/test0/ -size +20M -exec rm -rf {} \;
[root@xm test0]# ls -l
总用量 25600
-rw-r--r--. 1 root root  5242880 7月  15 17:41 a.mp4
drwxr-xr-x. 2 root root        6 7月  15 17:43 b
-rw-r--r--. 1 root root 20971520 7月  15 17:41 b.mp4

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

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


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

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


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

cp  /opt/test/b/ /opt/test0

24. 打开新的虚拟主机


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

[root@xm test0]# scp /home/bak.tar.gz root@192.168.2.12:/opt
root@192.168.2.12's password: 
bak.tar.gz                    100%  202   120.2KB/s   00:00 


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

[root@xm test0]# scp -r root@192.168.2.12:/etc/skel/  /opt
root@192.168.2.12's password: 
.bash_logout                  100%   18     5.5KB/s   00:00    
.bash_profile                 100%  193    69.8KB/s   00:00    
.bashrc                       100%  231   171.5KB/s   00:00  


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

[root@xm test0]# crontab -e

[root@xm test0]# ls /tmp
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值