练习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
[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
[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
[root@localhost ~]# mkdir /opt/test/a
[root@localhost ~]# ls /opt/test/
a abc.txt def.txt ghi.txt xxx.txt yyy.txt
[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
[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
[root@localhost ~]# find /opt/test/ -mtime +3 -exec rm -rf {} \;
[root@localhost ~]# find /opt/ -mtime -3 -exec rm -rf {} \;
[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
[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
[root@localhost ~]# mkdir /opt/test0
[root@localhost ~]# ls /opt/
a.txt d0 hhhhh.txt test test0
[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
[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
[root@localhost ~]# cp /opt/test0/*.mp4 /opt/test0/b
[root@localhost ~]# ls /opt/test0/b
a.mp4 b.mp4 c.mp4
[root@localhost ~]# find /opt/test0 -size +20M -exec rm -rf {} \;
您在 /var/spool/mail/root 中有新邮件
[root@localhost ~]# ls /opt/test0
a.mp4 b b.mp4
[root@localhost ~]# find /opt/test0/ -size -20M -exec rm -rf {} \;
[root@localhost ~]# find /opt/test0/ -size 20M -exec rm -rf {} \;
[root@localhost ~]# cp /opt/test0/b/*.mp4 /opt/test0
[root@localhost ~]# scp root@192.168.2.30:/bak.tar.gz /opt
scp root@192.168.2.31:/etc/skel/ /opt
[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