第二周day01练习

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

[root@localhost ~]# ls -l /etc/
总用量 1064
-rw-r--r--.  1 root root       16 5月  25 16:53 adjtime
-rw-r--r--.  1 root root     1518 6月   7 2013 aliases
-rw-r--r--.  1 root root    12288 5月  25 16:55 aliases.db
drwxr-xr-x.  2 root root       44 7月  11 18:14 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 5月  25 16:52 audisp
drwxr-x---.  3 root root       83 5月  25 16:55 audit
drwxr-xr-x.  2 root root       22 5月  25 16:52 bash_completion.d
-rw-r--r--.  1 root root     2853 4月  11 2018 bashrc
drwxr-xr-x.  2 root root        6 4月  11 2018 binfmt.d
-rw-r--r--.  1 root root       38 4月  29 2018 centos-release
-rw-r--r--.  1 root root       51 4月  29 2018 centos-release-upstream
drwxr-xr-x.  2 root root        6 8月   4 2017 chkconfig.d
-rw-r--r--.  1 root root     1108 4月  13 2018 chrony.conf
-rw-r-----.  1 root chrony    481 9月  15 2017 chrony.keys
drwxr-xr-x.  2 root root       21 5月  25 16:52 cron.d
drwxr-xr-x.  2 root root       42 5月  25 16:52 cron.daily
-rw-------.  1 root root        0 4月  11 2018 cron.deny
drwxr-xr-x.  2 root root       22 6月  10 2014 cron.hourly
drwxr-xr-x.  2 root root        6 6月  10 2014 cron.monthly
-rw-r--r--.  1 root root      451 6月  10 2014 crontab
drwxr-xr-x.  2 root root        6 6月  10 2014 cron.weekly
-rw-------.  1 root root        0 5月  25 16:51 crypttab
-rw-r--r--.  1 root root     1620 4月  11 2018 csh.cshrc
-rw-r--r--.  1 root root      866 4月  11 2018 csh.login
drwxr-xr-x.  4 root root       78 5月  25 16:52 dbus-1
drwxr-xr-x.  2 root root       44 7月  11 11:31 default
drwxr-xr-x.  2 root root       23 5月  25 16:52 depmod.d
drwxr-x---.  4 root root       53 5月  25 16:52 dhcp
 

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

[root@localhost ~]# ls /etc/ *a* | grep -E [^/]*a[^/]*
anaconda-ks.cfg
apache-tomcat-10.1.25.tar.gz
apache-tomcat-9.0.91.tar.gz
a.txt
mysql-9.0.0-1.el7.x86_64.rpm-bundle.tar
mysql-community-embedded-compat-9.0.0-1.el7.x86_64.rpm
mysql-community-icu-data-files-9.0.0-1.el7.x86_64.rpm
mysql-community-libs-compat-9.0.0-1.el7.x86_64.rpm
openjdk-17.0.1_linux-x64_bin.tar.gz
redis-6.2.6.tar.gz
todolist.jar
apache-tomcat-9.0.91:
webapps
adjtime
aliases
aliases.db
alternatives
anacrontab
asound.conf
 

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

[root@localhost ~]# 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 5月  25 16:52 /etc/kdump.conf
-rw-r--r--. 1 root root  590 4月  11 2018 /etc/krb5.conf
-rw-r--r--. 1 root root   28 2月  28 2013 /etc/ld.so.conf
-rw-r-----. 1 root root  191 10月 12 2017 /etc/libaudit.conf
-rw-r--r--. 1 root root 2391 10月 13 2013 /etc/libuser.conf
-rw-r--r--. 1 root root   19 5月  25 16:53 /etc/locale.conf
-rw-r--r--. 1 root root  662 7月  31 2013 /etc/logrotate.conf
-rw-r--r--. 1 root root 5171 6月  10 2014 /etc/man_db.conf
-rw-r--r--. 1 root root  936 4月  11 2018 /etc/mke2fs.conf
-rw-r--r--. 1 root root 1746 5月  25 16:52 /etc/nsswitch.conf
-rw-r--r--. 1 root root  101 7月  15 08:50 /etc/resolv.conf
-rw-r--r--. 1 root root 3232 4月  11 2018 /etc/rsyslog.conf
-rw-r--r--. 1 root root  216 4月  12 2018 /etc/sestatus.conf
-rw-r-----. 1 root root 1786 4月  11 2018 /etc/sudo.conf
-rw-r-----. 1 root root 3181 4月  11 2018 /etc/sudo-ldap.conf
-rw-r--r--. 1 root root  449 4月  11 2018 /etc/sysctl.conf
-rw-r--r--. 1 root root   37 5月  25 16:53 /etc/vconsole.conf
-rw-r--r--. 1 root root  970 4月  13 2018 /etc/yum.conf
 

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

[root@localhost ~]# 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 5月  25 16:53 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 43 7月   8 11:04 hh.repo

 

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

[root@localhost ~]# find /var/ -type f  -name "*.log"
/var/log/tuned/tuned.log
/var/log/audit/audit.log
/var/log/anaconda/anaconda.log
/var/log/anaconda/X.log
/var/log/anaconda/program.log
/var/log/anaconda/packaging.log
/var/log/anaconda/storage.log
/var/log/anaconda/ifcfg.log
/var/log/anaconda/ks-script-ND2_ph.log
/var/log/anaconda/ks-script-ORXzhM.log
/var/log/anaconda/journal.log
/var/log/boot.log
/var/log/vmware-vmsvc.log
/var/log/yum.log
/var/log/mysqld.log
 

练习6在opt⽬录下创建test⽬录

[root@localhost ~]# mkdir /opt/test
[root@localhost ~]# ls /opt
a.txt  d0  test

练习7在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 
[root@localhost ~]# ls -l /opt/test/
总用量 0
-rw-r--r--. 1 root root 0 7月  15 16:00 abc.txt
-rw-r--r--. 1 root root 0 7月  15 16:00 def.txt
-rw-r--r--. 1 root root 0 7月  15 16:00 ghi.txt
-rw-r--r--. 1 root root 0 7月  15 16:00 xxx.txt
-rw-r--r--. 1 root root 0 7月  15 16:00 yyy.txt
练习8 修改以上5个⽂件的最后修改时间分别为15,14,13,12,11,10⽇
[root@localhost ~]# touch -m -d "2024-7-15 00:00" /opt/test/abc.txt 
[root@localhost ~]# touch -m -d "2024-7-14 00:00" /opt/test/def.txt 
[root@localhost ~]# touch -m -d "2024-7-13 00:00" /opt/test/ghi.txt 
[root@localhost ~]# touch -m -d "2024-7-12 00:00" /opt/test/xxx.txt 
[root@localhost ~]# touch -m -d "2024-7-11 00:00" /opt/test/yyy.txt 
[root@localhost ~]# 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@localhost ~]# mkdir /opt/test/a
[root@localhost ~]# ls /opt/test/
a  abc.txt  def.txt  ghi.txt  xxx.txt  yyy.txt

 
练习10将以上5个⽂件复制⼀份到a⽬录中
[root@localhost ~]# cp /opt/test/*.txt /opt/test/a
[root@localhost ~]# ls /opt/test/a
abc.txt  def.txt  ghi.txt  test  xxx.txt  yyy.txt

 
练习11将a⽬录⽂件做成bak.tar.gz⽂件保存到家⽬录中
[root@localhost ~]# tar -czvf root/bak.tar.gz /opt/test/a
tar: 从成员名中删除开头的“/”
/opt/test/a/
/opt/test/a/test/
/opt/test/a/test/abc.txt
/opt/test/a/test/def.txt
/opt/test/a/test/ghi.txt
/opt/test/a/test/xxx.txt
/opt/test/a/test/yyy.txt
/opt/test/a/test/a/
/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天前的⽂件13. find删除opt⽬录下3天内的⽂件
[root@localhost ~]# find /opt/test/ -mtime +3 -exec rm -rf {} \;
[root@localhost ~]# find /opt/ -mtime -3 -exec rm -rf {} \;
练习14find删除正好第三天的⽂件
[root@localhost ~]# find /opt/test -type f -mtime 2 -exec rm -f {} \;
[root@localhost ~]# ls /opt/test/
a  abc.txt   def.txt  def.txt   xxx.txt  xxx.txt   yyy.txt 
[root@localhost ~]# ls -l /opt/test/
总用量 0
drwxr-xr-x. 2 root root 51 7月  15 16:37 a
-rw-r--r--. 1 root root  0 7月  15 00:00 abc.txt 
-rw-r--r--. 1 root root  0 7月  15 16:31 def.txt
-rw-r--r--. 1 root root  0 7月  14 00:00 def.txt 
-rw-r--r--. 1 root root  0 7月  15 16:35 xxx.txt
-rw-r--r--. 1 root root  0 7月  12 00:00 xxx.txt 
-rw-r--r--. 1 root root  0 7月  15 16:36 yyy.txt 
练习15将/opt/test/a⽬录中的⽂件复制⼀份到/opt/test/⽬录下
[root@localhost ~]# cp /opt/test/a/*.txt /opt/test/
cp:是否覆盖"/opt/test/def.txt"? yes
cp:是否覆盖"/opt/test/xxx.txt"? yes
您在 /var/spool/mail/root 中有新邮件
[root@localhost ~]# ls /opt/test/
a  abc.txt   def.txt  def.txt   xxx.txt  xxx.txt   yyy.txt  yyy.txt 

 
练习16创建⽬录/opt/test0
[root@localhost ~]# mkdir /opt/test0
[root@localhost ~]# ls /opt/
a.txt  d0  hhhhh.txt  test  test0

 
练习17在/opt/test0/⽬录中创建三个⽂件 a.mp4(5M),b.mp4(20M),c.mp4(80M)
[root@localhost ~]# dd if=/dev/zero of=/opt/test0/a.mp4 bs=5M count=1
记录了1+0 的读入
记录了1+0 的写出
5242880字节(5.2 MB)已复制,0.0029414 秒,1.8 GB/秒
[root@localhost ~]# dd if=/dev/zero of=/opt/test0/b.mp4 bs=20M count=1 
记录了1+0 的读入
记录了1+0 的写出
20971520字节(21 MB)已复制,0.0232739 秒,901 MB/秒
[root@localhost ~]# dd if=/dev/zero of=/opt/test0/c.mp4 bs=80M count=1 
记录了1+0 的读入
记录了1+0 的写出
83886080字节(84 MB)已复制,0.215882 秒,389 MB/秒
[root@localhost ~]# ls -l /opt/test0
总用量 107520
-rw-r--r--. 1 root root  5242880 7月  15 16:50 a.mp4
-rw-r--r--. 1 root root 20971520 7月  15 16:51 b.mp4
-rw-r--r--. 1 root root 83886080 7月  15 16:51 c.mp4
练习18创建⽬录/opt/test0/b/
[root@localhost ~]# touch /opt/test0/b
[root@localhost ~]# ls -l /opt/test0
总用量 107520
-rw-r--r--. 1 root root  5242880 7月  15 16:50 a.mp4
-rw-r--r--. 1 root root        0 7月  15 16:52 b
-rw-r--r--. 1 root root 20971520 7月  15 16:51 b.mp4
-rw-r--r--. 1 root root 83886080 7月  15 16:51 c.mp4

 
练习19将/op t/test0/中的⽂件复制⼀份/opt/test0/b/⽬录中
[root@localhost ~]# cp /opt/test0/*.mp4 /opt/test0/b
[root@localhost ~]# ls /opt/test0/b
a.mp4  b.mp4  c.mp4

 
练习20find查询/opt/test0/⽬录中⽂件⼤于20M的,并删除
[root@localhost ~]# find /opt/test0 -size +20M -exec rm -rf {} \;
您在 /var/spool/mail/root 中有新邮件
[root@localhost ~]# ls /opt/test0
a.mp4  b  b.mp4

 
练习21find查询/opt/test0/⽬录中⽂件⼩于20M的⽂件并删除
[root@localhost ~]# find /opt/test0/ -size -20M -exec  rm -rf {} \;
 
练习22find查找/opt/test0/⽬录中⽂件size为20M的⽂件并删除
[root@localhost ~]# find /opt/test0/ -size 20M -exec  rm -rf {} \;
 
练习23/opt/test0/b中的⽂件复制⼀份到/opt/test0中
[root@localhost ~]# cp /opt/test0/b/*.mp4 /opt/test0
 
练习24打开新的虚拟主机
练习25将家⽬录中的bak.tar.gz⽂件上传到新主机的/opt⽬录中
[root@localhost ~]# scp root@192.168.2.30:/bak.tar.gz /opt
 
练习26将新主机的/e tc/skel/⽬录下载到 当前主机的/opt⽬录中
scp root@192.168.2.31:/etc/skel/ /opt
 
练习27设置计划任务,每周3将/e tc/yum.repos.d/⽬录下的.repo⽂件压缩保存到tmp,在⽂件
名中添加时间戳
[root@localhost ~]# crontab -e
crontab: installing new crontab
您在 /var/spool/mail/root 中有新邮件
[root@localhost ~]# crontab -l
* * * * 3 /etc/yum.repos.d/*.repo/ tar -zcvf /tmp/etc_$(date "+\%Y\%m\%d\%H\%M\%S").tar.gz /etc                                                                                             
  • 13
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值