day06(7/15)——练习

练习:

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

[root@wanghan ~]# ls /etc
adjtime                  hosts                     rc1.d
aliases                  hosts.allow               rc2.d
aliases.db               hosts.deny                rc3.d
alternatives             init.d                    rc4.d
anacrontab               inittab                   rc5.d
asound.conf              inputrc                   rc6.d
audisp                   iproute2                  rc.d
audit                    issue                     rc.local
bash_completion.d        issue.net                 redhat-release
bashrc                   kdump.conf                resolv.conf
binfmt.d                 kernel                    resolv.conf.save
centos-release           krb5.conf                 rpc
centos-release-upstream  krb5.conf.d               rpm
chkconfig.d              ld.so.cache               rsyslog.conf
chrony.conf              ld.so.conf                rsyslog.d
chrony.keys              ld.so.conf.d              rwtab
cron.d                   libaudit.conf             rwtab.d
cron.daily               libnl                     sasl2
cron.deny                libuser.conf              securetty
cron.hourly              locale.conf               security
cron.monthly             localtime                 selinux
crontab                  login.defs                services
cron.weekly              logrotate.conf            sestatus.conf
crypttab                 logrotate.d               shadow
csh.cshrc                lvm                       shadow-
csh.login                machine-id                shells
dbus-1                   magic                     skel
default                  makedumpfile.conf.sample  ssh
depmod.d                 man_db.conf               ssl
dhcp                     mke2fs.conf               statetab
DIR_COLORS               modprobe.d                statetab.d
DIR_COLORS.256color      modules-load.d            subgid
DIR_COLORS.lightbgcolor  motd                      subuid
dracut.conf              mtab                      sudo.conf
dracut.conf.d            my.cnf                    sudoers
e2fsck.conf              my.cnf.d                  sudoers.d
environment              NetworkManager            sudo-ldap.conf
ethertypes               networks                  sysconfig
exports                  nsswitch.conf             sysctl.conf
favicon.png              nsswitch.conf.bak         sysctl.d
filesystems              openldap                  systemd
firewalld                opt                       system-release
fonts                    os-release                system-release-cpe
fstab                    pam.d                     terminfo
fuse.conf                passwd                    tmpfiles.d
gcrypt                   passwd-                   tuned
GeoIP.conf               pkcs11                    udev
GeoIP.conf.default       pki                       vconsole.conf
gnupg                    plymouth                  vimrc
GREP_COLORS              pm                        virc
groff                    polkit-1                  vmware-tools
group                    popt.d                    vsftpd
group-                   ppp                       wgetrc
grub2.cfg                prelink.conf.d            wpa_supplicant
grub.d                   printcap                  X11
gshadow                  profile                   xdg
gshadow-                 profile.d                 xinetd.d
gss                      protocols                 yum
host.conf                python                    yum.conf
hostname                 rc0.d                     yum.repos.d

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

[root@wanghan ~]# ls /etc/*a*
/etc/adjtime                  /etc/gshadow-                  /etc/os-release
/etc/aliases                  /etc/hostname                  /etc/passwd
/etc/aliases.db               /etc/hosts.allow               /etc/passwd-
/etc/anacrontab               /etc/inittab                   /etc/printcap
/etc/asound.conf              /etc/ld.so.cache               /etc/rc.local
/etc/bashrc                   /etc/libaudit.conf             /etc/redhat-release
/etc/centos-release           /etc/locale.conf               /etc/resolv.conf.save
/etc/centos-release-upstream  /etc/localtime                 /etc/rwtab
/etc/crontab                  /etc/logrotate.conf            /etc/sestatus.conf
/etc/crypttab                 /etc/machine-id                /etc/shadow
/etc/dracut.conf              /etc/magic                     /etc/shadow-
/etc/favicon.png              /etc/makedumpfile.conf.sample  /etc/statetab
/etc/fstab                    /etc/man_db.conf               /etc/sudo-ldap.conf
/etc/GeoIP.conf.default       /etc/mtab                      /etc/system-release
/etc/gshadow                  /etc/nsswitch.conf.bak         /etc/system-release-cpe

/etc/alternatives:
ld  libnssckbi.so.x86_64

/etc/audisp:
audispd.conf  plugins.d

/etc/audit:
auditd.conf  audit.rules  audit-stop.rules  rules.d

/etc/bash_completion.d:
iprutils

/etc/cron.daily:
logrotate  man-db.cron

/etc/default:
grub  nss  useradd

/etc/dracut.conf.d:

/etc/firewalld:
firewalld.conf  helpers  icmptypes  ipsets  lockdown-whitelist.xml  services  zones

/etc/logrotate.d:
bootlog  chrony  mysql  syslog  vsftpd  wpa_supplicant  yum

/etc/modules-load.d:

/etc/NetworkManager:
conf.d  dispatcher.d  dnsmasq.d  dnsmasq-shared.d  NetworkManager.conf  system-connections

/etc/openldap:
certs  ldap.conf

/etc/pam.d:
chfn                 other             remote             sudo            vmtoolsd
chsh                 passwd            runuser            sudo-i          vsftpd
config-util          password-auth     runuser-l          su-l            vsftpd.YYYYMMDD
crond                password-auth-ac  smartcard-auth     system-auth
fingerprint-auth     polkit-1          smartcard-auth-ac  system-auth-ac
fingerprint-auth-ac  postlogin         sshd               systemd-user
login                postlogin-ac      su                 vlock

/etc/rwtab.d:
logrotate

/etc/sasl2:

/etc/statetab.d:

/etc/vmware-tools:
GuestProxyData       poweroff-vm-default  resume-vm-default  statechange.subr    vgauth
guestproxy-ssl.conf  poweron-vm-default   scripts            suspend-vm-default  vgauth.conf

/etc/wpa_supplicant:
wpa_supplicant.conf

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

[root@wanghan ~]# ls /etc/*.conf
/etc/asound.conf  /etc/GeoIP.conf  /etc/libaudit.conf   /etc/mke2fs.conf    /etc/sudo.conf
/etc/chrony.conf  /etc/host.conf   /etc/libuser.conf    /etc/nsswitch.conf  /etc/sudo-ldap.conf
/etc/dracut.conf  /etc/kdump.conf  /etc/locale.conf     /etc/resolv.conf    /etc/sysctl.conf
/etc/e2fsck.conf  /etc/krb5.conf   /etc/logrotate.conf  /etc/rsyslog.conf   /etc/vconsole.conf
/etc/fuse.conf    /etc/ld.so.conf  /etc/man_db.conf     /etc/sestatus.conf  /etc/yum.conf

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

[root@wanghan ~]# ls /etc/y*
/etc/yum.conf

/etc/yum:
fssnap.d  pluginconf.d  protected.d  vars  version-groups.conf

/etc/yum.repos.d:
wh.repo

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

[root@wanghan ~]# find /var  -name "*.log" -type f
/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-T2QIIP.log
/var/log/anaconda/ks-script-UzpUeZ.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@wanghan ~]# mkdir /opt/test
[root@wanghan ~]# cd /opt
[root@wanghan opt]# ls
a.txt  b.txt  c.txt  d.txt  test

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

[root@wanghan ~]# touch /opt/test/abc.txt /opt/test/def.txt /opt/test/ghi.txt /opt/test/xxx.txt /opt/test/yyy.txt
[root@wanghan opt]# cd test
[root@wanghan test]# ls
abc.txt  def.txt  ghi.txt  xxx.txt  yyy.txt
[root@wanghan test]# ls -l 
总用量 0
-rw-r--r--. 1 root root 0 7月  15 00:00 abc.txt
-rw-r--r--. 1 root root 0 7月  16 03:17 def.txt
-rw-r--r--. 1 root root 0 7月  16 03:17 ghi.txt
-rw-r--r--. 1 root root 0 7月  16 03:17 xxx.txt
-rw-r--r--. 1 root root 0 7月  16 03:17 yyy.txt

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

[root@wanghan test]# touch /opt/test/abc.txt -m -d "2024-07-15 00:00"
[root@wanghan test]# touch /opt/test/def.txt -m -d "2024-07-14 00:00"
[root@wanghan test]# touch /opt/test/ghi.txt -m -d "2024-07-13 00:00"
[root@wanghan test]# touch /opt/test/xxx.txt -m -d "2024-07-12 00:00"
[root@wanghan test]# touch /opt/test/yyy.txt -m -d "2024-07-11 00:00"
[root@wanghan test]# ls -l
总用量 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@wanghan test]# mkdir a
[root@wanghan test]# ls
a  abc.txt  def.txt  ghi.txt  xxx.txt  yyy.txt

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

[root@wanghan test]# cp /opt/test/abc.txt /opt/test/def.txt /opt/test/ghi.txt /opt/test/xxx.txt /opt/test/yyy.txt /opt/test/a
[root@wanghan test]# ls -l /opt/test/a
总用量 0
-rw-r--r--. 1 root root 0 7月  16 03:31 abc.txt
-rw-r--r--. 1 root root 0 7月  16 03:31 def.txt
-rw-r--r--. 1 root root 0 7月  16 03:31 ghi.txt
-rw-r--r--. 1 root root 0 7月  16 03:31 xxx.txt
-rw-r--r--. 1 root root 0 7月  16 03:31 yyy.txt

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

[root@wanghan ~]# cd /home
[root@wanghan home]# pwd
/home
[root@wanghan home]# ls /opt/test
a  abc.txt  def.txt  ghi.txt  xxx.txt  yyy.txt
[root@wanghan home]# tar -zcvf bak.tar.gz /opt/test/a
tar: 从成员名中删除开头的“/”
/opt/test/a/
[root@wanghan home]# ls
bak.tar.gz  ftpuser  user0  user1  user3  user4  wh

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

[root@wanghan test]# ls -l
总用量 0
drwxr-xr-x. 2 root root 6 7月  16 03:45 a
-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月  12 00:00 xxx.txt
-rw-r--r--. 1 root root 0 7月  11 00:00 yyy.txt
[root@wanghan test]# find /opt/test/ -mtime +3
/opt/test/xxx.txt
/opt/test/yyy.txt
[root@wanghan test]# find /opt/test/ -mtime +3 | xargs rm -rf
[root@wanghan test]# ls
a  abc.txt  def.txt

13. find删除opt⽬录下3天内的⽂件--原来的文件已经没有了

[root@wanghan test]# find /opt/* -mtime -3 -exec rm -rf {} \;
[root@wanghan test]# ls

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

[root@wanghan test]# ls -lh
总用量 0
drwxr-xr-x. 2 root root 6 7月  16 03:45 a
-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
[root@wanghan test]# find /opt/* -mtime 3 -exec rm -rf {} \;
[root@wanghan test]# ls -l
总用量 0
drwxr-xr-x. 2 root root 6 7月  16 03:45 a
-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月  12 00:00 xxx.txt
-rw-r--r--. 1 root root 0 7月  11 00:00 yyy.txt

 

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

[root@wanghan test]# ls
a
[root@wanghan a]# ls /opt/test/a/
abc.txt  def.txt  ghi.txt  xxx.txt  yyy.txt
[root@wanghan a]# cp /opt/test/a/* /opt/test/
[root@wanghan a]# ls /opt/test
a  abc.txt  def.txt  ghi.txt  xxx.txt  yyy.txt

16. 创建⽬录/opt/test0

[root@wanghan ~]# mkdir /opt/test0
[root@wanghan ~]# ls /opt/
d.txt  test  test0

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

[root@wanghan test0]# dd if=/dev/zero of=a.mp4 bs=5M count=1
记录了1+0 的读入
记录了1+0 的写出
5242880字节(5.2 MB)已复制,0.0332913 秒,157 MB/秒
[root@wanghan test0]# dd if=/dev/zero of=b.mp4 bs=20M count=1
记录了1+0 的读入
记录了1+0 的写出
20971520字节(21 MB)已复制,0.219214 秒,95.7 MB/秒
[root@wanghan test0]# dd if=/dev/zero of=c.mp4 bs=80M count=1
记录了1+0 的读入
记录了1+0 的写出
83886080字节(84 MB)已复制,1.12213 秒,74.8 MB/秒
[root@wanghan test0]# ls -l
总用量 107520
-rw-r--r--. 1 root root  5242880 7月  16 04:44 a.mp4
-rw-r--r--. 1 root root 20971520 7月  16 04:45 b.mp4
-rw-r--r--. 1 root root 83886080 7月  16 04:45 c.mp4
[root@wanghan test0]# 

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

[root@wanghan test0]# pwd
/opt/test0
[root@wanghan test0]# mkdir b
[root@wanghan test0]# ls
a.mp4  b  b.mp4  c.mp4
[root@wanghan test0]# 

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

[root@wanghan ~]# ls /opt/test0
a.mp4  b  b.mp4  c.mp4
[root@wanghan ~]# cp /opt/test0/* /opt/test0/b
cp: 略过目录"/opt/test0/b"
[root@wanghan ~]# ls /opt/test0/b
a.mp4  b.mp4  c.mp4
[root@wanghan ~]# 

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

[root@wanghan ~]# ls -l /opt/test0/
总用量 107520
-rw-r--r--. 1 root root  5242880 7月  16 04:44 a.mp4
drwxr-xr-x. 2 root root       45 7月  16 04:47 b
-rw-r--r--. 1 root root 20971520 7月  16 04:45 b.mp4
-rw-r--r--. 1 root root 83886080 7月  16 04:45 c.mp4
[root@wanghan ~]# find /opt/test0/ -size +20M -exec rm -rf {} \;
[root@wanghan ~]# ls -l /opt/test0/
总用量 25600
-rw-r--r--. 1 root root  5242880 7月  16 04:44 a.mp4
drwxr-xr-x. 2 root root       32 7月  16 04:49 b
-rw-r--r--. 1 root root 20971520 7月  16 04:45 b.mp4
[root@wanghan ~]# 

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

[root@wanghan ~]# ls -l /opt/test0/
总用量 25600
-rw-r--r--. 1 root root  5242880 7月  16 04:44 a.mp4
drwxr-xr-x. 2 root root       32 7月  16 04:49 b
-rw-r--r--. 1 root root 20971520 7月  16 04:45 b.mp4
[root@wanghan ~]# find /opt/test0/* -type f -size -20M -exec rm -rf {} \;
[root@wanghan ~]# ls -l /opt/test0/
总用量 20480
drwxr-xr-x. 2 root root       19 7月  16 04:50 b
-rw-r--r--. 1 root root 20971520 7月  16 04:45 b.mp4
[root@wanghan ~]# 

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

[root@wanghan ~]# ls -l /opt/test0/
总用量 20480
drwxr-xr-x. 2 root root       19 7月  16 04:50 b
-rw-r--r--. 1 root root 20971520 7月  16 04:45 b.mp4
[root@wanghan ~]# find /opt/test0/* -type f -size 20M -exec rm -rf {} \;
[root@wanghan ~]# ls -l /opt/test0/
总用量 0
drwxr-xr-x. 2 root root 6 7月  16 04:51 b
[root@wanghan ~]# 

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

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

24. 打开新的虚拟主机

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

 

[root@wanghan ~]# scp /home/bak.tar.gz root@192.168.1.22:/opt/
The authenticity of host '192.168.1.22 (192.168.1.22)' can't be established.
ECDSA key fingerprint is SHA256:+GuCHATLsbzVUOHRXKiw5ivBqzBcWVvSNrYsooKY5rY.
ECDSA key fingerprint is MD5:8b:3b:e4:81:4a:60:ed:04:0a:bd:b9:0c:80:af:dd:09.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.22' (ECDSA) to the list of known hosts.
root@192.168.1.22's password: 
[root@wanghan ~]# ls /home/
bak.tar.gz  ftpuser  user0  user1  user3  user4  wh

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

[root@wanghan ~]# scp -r root@192.168.1.22:/etc/skel/ /opt/
The authenticity of host '192.168.1.22 (192.168.1.22)' can't be established.
ECDSA key fingerprint is SHA256:+GuCHATLsbzVUOHRXKiw5ivBqzBcWVvSNrYsooKY5rY.
ECDSA key fingerprint is MD5:8b:3b:e4:81:4a:60:ed:04:0a:bd:b9:0c:80:af:dd:09.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.22' (ECDSA) to the list of known hosts.
root@192.168.1.22's password: 
.bash_logout                                         100%   18     7.2KB/s   00:00    
.bash_profile                                        100%  193   132.1KB/s   00:00    
.bashrc                                              100%  231   119.0KB/s   00:00    
[root@wanghan ~]# ls /opt/
a.txt  b.txt  c.txt  d.txt  skel
[root@wanghan ~]# 

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

[root@wanghan ~]# crontab -e


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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值