训练(能力提升)

练习1:使⽤ls查看/etc/⽬录下所有的⽂件信息
 [root@1 ~]# ls -l /etc
 总用量 1124
 -rw-r--r--.  1 root root       16 6月  21 02:03 adjtime
 -rw-r--r--.  1 root root     1518 6月   7 2013 aliases
 -rw-r--r--.  1 root root    12288 6月  21 02:06 aliases.db
 drwxr-xr-x.  2 root root       44 7月  11 17:39 alternatives
 -rw-------.  1 root root      541 4月  11 2018 anacrontab
 -rw-r--r--.  1 root root       55 4月  11 2018 asound.conf
 drwxr-x---.  3 root root       43 6月  21 02:01 audisp
 drwxr-x---.  3 root root       83 6月  21 02:06 audit
 drwxr-xr-x.  2 root root       46 7月   8 23:47 bash_completion.d
 ......
练习2:使⽤ls查看/etc/⽬录下名包含“a”字⺟的⽂件或者⽬录信息
 [root@1 ~]# ls -l /etc/*a*
 -rw-r--r--. 1 root root    16 6月  21 02:03 /etc/adjtime
 -rw-r--r--. 1 root root  1518 6月   7 2013 /etc/aliases
 -rw-r--r--. 1 root root 12288 6月  21 02:06 /etc/aliases.db
 -rw-------. 1 root root   541 4月  11 2018 /etc/anacrontab
 -rw-r--r--. 1 root root    55 4月  11 2018 /etc/asound.conf
 -rw-r--r--. 1 root root  2853 4月  11 2018 /etc/bashrc
 -rw-r--r--. 1 root root    38 4月  29 2018 /etc/centos-release
 -rw-r--r--. 1 root root    51 4月  29 2018 /etc/centos-release-upstream
 -rw-r--r--. 1 root root   451 6月  10 2014 /etc/crontab
 -rw-------. 1 root root     0 6月  21 01:59 /etc/crypttab
 -rw-r--r--. 1 root root  1285 4月  11 2018 /etc/dracut.conf
 lrwxrwxrwx. 1 root root    56 6月  21 02:00 /etc/favicon.png -> /usr/share/icons/hicolor/16x16/apps/fedora-logo-icon.png
 ......
练习3: 使⽤ls查看/etc/⽬录下以".conf"结尾的⽂件信息
 [root@1 ~]# ls -l /etc/*.conf
 -rw-r--r--. 1 root root   55 4月  11 2018 /etc/asound.conf
 -rw-r--r--. 1 root root 1108 4月  13 2018 /etc/chrony.conf
 -rw-r--r--. 1 root root 1285 4月  11 2018 /etc/dracut.conf
 -rw-r--r--. 1 root root  112 4月  11 2018 /etc/e2fsck.conf
 -rw-r--r--. 1 root root   38 4月  11 2018 /etc/fuse.conf
 -rw-r--r--. 1 root root  842 11月  6 2016 /etc/GeoIP.conf
 -rw-r--r--. 1 root root    9 6月   7 2013 /etc/host.conf
 -rw-r--r--. 1 root root 7265 6月  21 02:01 /etc/kdump.conf
 ......
练习4: 使⽤ls查看/etc/⽬录中以"y"字⺟开头的⽂件信息
 [root@1 ~]# ls -l /etc/y*
 -rw-r--r--. 1 root root 970 4月  13 2018 /etc/yum.conf
 ​
 /etc/yum:
 总用量 4
 drwxr-xr-x. 2 root root   6 4月  13 2018 fssnap.d
 drwxr-xr-x. 2 root root  54 6月  21 02:03 pluginconf.d
 drwxr-xr-x. 2 root root  26 4月  13 2018 protected.d
 drwxr-xr-x. 2 root root  37 4月  13 2018 vars
 -rw-r--r--. 1 root root 444 4月  13 2018 version-groups.conf
 ​
 /etc/yum.repos.d:
 总用量 4
 -rw-r--r--. 1 root root 42 7月   8 18:56 hh.repo
练习5: find查找/var/⽬录中以“.log”⽂件
 [root@1 ~]# find /var/*.log
 find: ‘/var/*.log’: 没有那个文件或目录
练习6:在opt⽬录下创建test⽬录
 [root@1 ~]# mkdir /opt/test
 [root@1 ~]# ls /opt
 test
练习7: 在test⽬录中创建abc.txt,def.txt.ghi.txt,xxx.txt.yyy.txt五个⽂件
 [root@1 ~]# touch /opt/test/abc.txt /opt/test/def.txt /opt/test/ghi.txt /opt/test/xxx.txt /opt/test/yyy.txt
 [root@1 ~]# ls /opt/test/
 abc.txt  def.txt  ghi.txt  xxx.txt  yyy.txt
练习8:修改以上5个⽂件的最后修改时间分别为15,14,13,12,11⽇
 [root@1 ~]# touch /opt/test/abc.txt -m -d "2024-7-15 00:00"
 [root@1 ~]# touch /opt/test/def.txt -m -d "2024-7-14 00:00"
 [root@1 ~]# touch /opt/test/ghi.txt -m -d "2024-7-13 00:00"
 [root@1 ~]# touch /opt/test/xxx.txt -m -d "2024-7-12 00:00"
 [root@1 ~]# touch /opt/test/yyy.txt -m -d "2024-7-11 00:00"
 [root@1 test]# ls -l /opt/test
 总用量 0
 -rw-r--r--. 1 root root  0 7月  15 00:00 abc.txt
 -rw-r--r--. 1 root root  0 7月  14 00:00 def.txt
 -rw-r--r--. 1 root root  0 7月  13 00:00 ghi.txt
 -rw-r--r--. 1 root root  0 7月  12 00:00 xxx.txt
 -rw-r--r--. 1 root root  0 7月  11 00:00 yyy.txt
 ​
练习9:在test⽬录下创建a⽬录
 [root@1 ~]# mkdir /opt/test/a
 [root@1 ~]# ls /opt/test/
 a  abc.txt  def.txt  ghi.txt  xxx.txt  yyy.txt
练习10:将以上5个⽂件复制⼀份到a⽬录中
 [root@1 ~]# cp /opt/test/*.txt /opt/test/a
 [root@1 ~]# tree /opt/test/
 /opt/test/
 ├── a
 │   ├── abc.txt
 │   ├── def.txt
 │   ├── ghi.txt
 │   ├── xxx.txt
 │   └── yyy.txt
 ├── abc.txt
 ├── def.txt
 ├── ghi.txt
 ├── xxx.txt
 └── yyy.txt
 ​
 1 directory, 10 files
练习11: 将a⽬录⽂件做成bak.tar.gz⽂件保存到家⽬录中
 [root@1 ~]# tar -czvf bak.tar.gz /opt/test/a/* 
 tar: 从成员名中删除开头的“/”
 /opt/test/a/abc.txt
 /opt/test/a/def.txt
 /opt/test/a/ghi.txt
 /opt/test/a/xxx.txt
 /opt/test/a/yyy.txt
 [root@1 ~]# ls
 bak.tar.gz
 [root@1 ~]# tar -tf bak.tar.gz 
 opt/test/a/abc.txt
 opt/test/a/def.txt
 opt/test/a/ghi.txt
 opt/test/a/xxx.txt
 opt/test/a/yyy.txt
练习12:使⽤find删除test⽬录下3天前的⽂件 练习
 [root@1 ~]# find /opt/test/ -mtime +3
 /opt/test/yyy.txt
 [root@1 ~]# find /opt/test/*.txt -mtime +3 | xargs rm
 [root@1 ~]# ls /opt/test/
 a  abc.txt  def.txt  ghi.txt  xxx.txt
练习13: find删除opt⽬录下3天内的⽂件
 [root@1 ~]# find /opt/test/*.txt -mtime -3 -exec rm -rf {} \;
 [root@1 ~]# ls /opt/test/
 a xxx.txt  
练习14: find删除正好第三天的⽂件
 [root@1 ~]# find /opt/test/*.txt -mtime 3 | xargs rm
 [root@1 ~]# ls /opt/test/
 a
练习15: 将/opt/test/a⽬录中的⽂件复制i⼀份到/opt/test/⽬录下
 [root@1 ~]# cp /opt/test/a/* /opt/test/
 [root@1 ~]# ls /opt/test/
 a  abc.txt  def.txt  ghi.txt  xxx.txt  yyy.txt
练习16: 创建⽬录/opt/test0
 [root@1 ~]# ls /opt
 test   test0
练习17: 在/opt/test0/⽬录中创建三个⽂件 a.mp4(5M),b.mp4(20M),c.mp4(80M)
 [root@1 ~]# dd if=/dev/zero of=/opt/test0/a.mp4 bs=5M count=1
 记录了1+0 的读入
 记录了1+0 的写出
 5242880字节(5.2 MB)已复制,0.0489333 秒,107 MB/秒
 [root@1 ~]# dd if=/dev/zero of=/opt/test0/b.mp4 bs=20M count=1
 记录了1+0 的读入
 记录了1+0 的写出
 20971520字节(21 MB)已复制,0.165335 秒,127 MB/秒
 [root@1 ~]# dd if=/dev/zero of=/opt/test0/c.mp4 bs=80M count=1
 记录了1+0 的读入
 记录了1+0 的写出
 83886080字节(84 MB)已复制,1.16632 秒,71.9 MB/秒
 [root@1 ~]# ls -lh /opt/test0/
 总用量 105M
 -rw-r--r--. 1 root root 5.0M 7月  15 19:37 a.mp4
 -rw-r--r--. 1 root root  20M 7月  15 19:37 b.mp4
 -rw-r--r--. 1 root root  80M 7月  15 19:38 c.mp4
练习18: 创建⽬录/opt/test0/b/
 [root@1 ~]# mkdir /opt/test0/b/
 [root@1 ~]# ls /opt/test0/
 a.mp4  b  b.mp4  c.mp4
练习19:将/op t/test0/中的⽂件复制⼀份/opt/test0/b/⽬录中
 [root@1 ~]# cp /opt/test0/* /opt/test0/b/
 cp: 略过目录"/opt/test0/b"
 [root@1 ~]# ls /opt/test0/b
 a.mp4  b.mp4  c.mp4
练习20:find查询/opt/test0/⽬录中⽂件⼤于20M的,并删除
 [root@1 ~]# find /opt/test0/*.mp4 -size +20M
 /opt/test0/c.mp4
 [root@1 ~]# find /opt/test0/*.mp4 -size +20M -exec rm {} \;
 [root@1 ~]# ls -lh /opt/test0
 总用量 25M
 -rw-r--r--. 1 root root 5.0M 7月  15 19:37 a.mp4
 drwxr-xr-x. 2 root root   45 7月  15 19:39 b
 -rw-r--r--. 1 root root  20M 7月  15 19:37 b.mp4
练习21: find查询/opt/test0/⽬录中⽂件⼩于20M的⽂件并删除
 [root@1 ~]# find /opt/test0/*.mp4 -size -20M | xargs rm 
 [root@1 ~]# ls -lh /opt/test0
 总用量 20M
 drwxr-xr-x. 2 root root  45 7月  15 19:39 b
 -rw-r--r--. 1 root root 20M 7月  15 19:37 b.mp4
练习22: find查找/opt/test0/⽬录中⽂件size为20M的⽂件并删除
 [root@1 ~]# find /opt/test0/*.mp4 -size 20M | xargs rm 
 [root@1 ~]# ls -lh /opt/test0
 总用量 0
 drwxr-xr-x. 2 root root 45 7月  15 19:39 b
练习23: /opt/test0/b中的⽂件复制⼀份到/opt/test0中
 [root@1 ~]# cp /opt/test0/b/* /opt/test0
 [root@1 ~]# ls /opt/test0
 a.mp4  b  b.mp4  c.mp4
练习24:打开新的虚拟主机
 [D:\~]$ 
 ​
 Connecting to 10.0.0.20:22...
 Connection established.
 To escape to local shell, press Ctrl+Alt+].
 ​
 WARNING! The remote SSH server rejected X11 forwarding request.
 Last login: Mon Jul 15 17:28:16 2024 from 10.0.0.1
练习25:将家⽬录中的bak.tar.gz⽂件上传到新主机的/opt⽬录中
 1:
 [root@1 ~]# scp bak.tar.gz root@10.0.0.20:/opt
 root@10.0.0.20's password: 
 bak.tar.gz  100%  166   107.6KB/s   00:00   
 2:
 [root@2 ~]# ls /opt
 bak.tar.gz 
练习26:将新主机的/e tc/skel/⽬录下载到 当前主机的/opt⽬录中
 [root@1 ~]# scp -r root@10.0.0.20:/etc/skel /opt
 root@10.0.0.20's password: 
 .bash_logout                                                  100%   18     5.8KB/s   00:00    
 .bash_profile                                                 100%  193    52.9KB/s   00:00    
 .bashrc                                                       100%  231    80.0KB/s   00:00  
练习27:设置计划任务,每周3将/e tc/yum.repos.d/⽬录下的.repo⽂件压缩保存到tmp,在⽂件 名中添加时间戳
 [root@1 ~]# crontab -e
 * * * * */3 /usr/bin/tar -czvf /tmp/repo_$(date "+\%Y\%m\%d\%H\%M\%S").tar.gz  /etc/yum.repos.d/*.repo 
 crontab: installing new crontab
 [root@1 ~]# ls /tmp
 repo_20240715195501.tar.gz

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值