练习linux

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

[root@localhost ~]# ls -l /etc
总用量 1124
-rw-r--r--.  1 root root       16 6月  21 16:49 adjtime
-rw-r--r--.  1 root root     1518 6月   7 2013 aliases
-rw-r--r--.  1 root root    12288 6月  21 16:50 aliases.db
drwxr-xr-x.  2 root root      236 7月   9 21:42 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 16:47 audisp
drwxr-x---.  3 root root       83 6月  21 16:50 audit
drwxr-xr-x.  2 root root       46 6月  21 17:01 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
.......

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

[root@localhost ~]# ls -l /etc/*a*
-rw-r--r--. 1 root root    16 6月  21 16:49 /etc/adjtime
-rw-r--r--. 1 root root  1518 6月   7 2013 /etc/aliases
-rw-r--r--. 1 root root 12288 6月  21 16:50 /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 16:47 /etc/crypttab
-rw-r--r--. 1 root root  1285 4月  11 2018 /etc/dracut.conf
lrwxrwxrwx. 1 root root    56 6月  21 16:47 /etc/favicon.png -> /usr/share/icons/hicolor/16x16/apps/fedora-logo-icon.png
-rw-r--r--. 1 root root   502 6月  21 16:55 /etc/fstab
-rw-r--r--. 1 root root   858 11月  6 2016 /etc/GeoIP.conf.default
----------. 1 root root   367 7月  15 17:23 /etc/gshadow
----------. 1 root root   356 6月  21 16:47 /etc/gshadow-
-rw-r--r--. 1 root root    22 6月  21 16:49 /etc/hostname
-rw-r--r--. 1 root root   370 6月   7 2013 /etc/hosts.allow
......

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 6月  21 16:47 /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 6月  21 16:49 /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 6月  21 16:47 /etc/nsswitch.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 6月  21 16:49 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 6月  21 17:00 haha.repo
[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 6月  21 16:49 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
......

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

[root@localhost ~]# find /var -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-g9KXeE.log
/var/log/anaconda/ks-script-jlP7_R.log
/var/log/anaconda/journal.log
/var/log/boot.log
/var/log/vmware-vmsvc.log
/var/log/yum.log
/var/log/redis_6379.log
 

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

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

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

[root@localhost ~]# touch /opt/test/abc.txt /opt/test/def.txt /opt/test/ghi.txt /opt/test/xxx.txt /opt/test/yyy.txt
[root@localhost ~]# ls /opt/test
abc.txt  def.txt  ghi.txt  xxx.txt  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/*.txt
-rw-r--r--. 1 root root 0 7月  15 00:00 /opt/test/abc.txt
-rw-r--r--. 1 root root 0 7月  14 00:00 /opt/test/def.txt
-rw-r--r--. 1 root root 0 7月  13 00:00 /opt/test/ghi.txt
-rw-r--r--. 1 root root 0 7月  12 00:00 /opt/test/xxx.txt
-rw-r--r--. 1 root root 0 7月  11 00:00 /opt/test/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/abc.txt /opt/test/a/
[root@localhost ~]# cp /opt/test/def.txt /opt/test/a/
[root@localhost ~]# cp /opt/test/ghi.txt /opt/test/a/
[root@localhost ~]# cp /opt/test/xxx.txt /opt/test/a/
[root@localhost ~]# cp /opt/test/yyy.txt /opt/test/a/

[root@localhost ~]# ls /opt/test
a  abc.txt  def.txt  ghi.txt  xxx.txt  yyy.txt

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

[root@localhost ~]# tar -czvf ~/bak.tar.gz /opt/test/a
tar: 从成员名中删除开头的“/”
/opt/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天前的⽂件

[root@localhost ~]# find /opt/test -type f -mtime +3
/opt/test/xxx.txt
/opt/test/yyy.txt
[root@localhost ~]# find /opt/test -name "*.txt" -type f -mtime +3 -exec rm -rf {} \;
[root@localhost ~]# ls -l /opt/test/*.txt
-rw-r--r--. 1 root root 0 7月  15 00:00 /opt/test/abc.txt
-rw-r--r--. 1 root root 0 7月  14 00:00 /opt/test/def.txt
-rw-r--r--. 1 root root 0 7月  13 00:00 /opt/test/ghi.txt
 

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

[root@localhost ~]# find /opt/ -type f -mtime -3
/opt/a.txt
/opt/d0/a.txt
/opt/d0/b.txt
/opt/d0/c.txt
/opt/test/abc.txt
/opt/test/def.txt
/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
/opt/abc.txt
/opt/def.txt
[root@localhost ~]# find /opt/ -type f -mtime -3 -exec rm -rf {} \;
[root@localhost ~]# ls -l /opt/
总用量 0
-rw-r--r--. 1 root root  0 7月  11 00:00 b.txt
-rw-r--r--. 1 root root  0 7月  10 00:00 c.txt
drwxr-xr-x. 2 root root  6 7月  16 03:36 d0
-rw-r--r--. 1 root root  0 7月   9 00:00 d.txt
-rw-r--r--. 1 root root  0 7月   8 00:00 e.txt
-rw-r--r--. 1 root root  0 7月  13 00:00 ghi.txt
drwxr-xr-x. 3 root root 30 7月  16 03:36 test
-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
 

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

[root@localhost ~]# ls -l /opt/
总用量 0
-rw-r--r--. 1 root root  0 7月  11 00:00 b.txt
-rw-r--r--. 1 root root  0 7月  10 00:00 c.txt
drwxr-xr-x. 2 root root  6 7月  16 03:36 d0
-rw-r--r--. 1 root root  0 7月   9 00:00 d.txt
-rw-r--r--. 1 root root  0 7月   8 00:00 e.txt
-rw-r--r--. 1 root root  0 7月  13 00:00 ghi.txt
drwxr-xr-x. 3 root root 30 7月  16 03:36 test
-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 ~]# find /opt/ -type f -mtime 3
/opt/test/ghi.txt
/opt/ghi.txt
[root@localhost ~]# find /opt/ -type f -mtime 3 -exec rm -rf {} \;
[root@localhost ~]# ls -l /opt/
总用量 0
-rw-r--r--. 1 root root  0 7月  11 00:00 b.txt
-rw-r--r--. 1 root root  0 7月  10 00:00 c.txt
drwxr-xr-x. 2 root root  6 7月  16 03:36 d0
-rw-r--r--. 1 root root  0 7月   9 00:00 d.txt
-rw-r--r--. 1 root root  0 7月   8 00:00 e.txt
drwxr-xr-x. 3 root root 15 7月  16 03:37 test
-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@localhost ~]# touch /opt/test/a/hahah.txt
[root@localhost ~]# ls -l /opt/test/a
总用量 0
-rw-r--r--. 1 root root 0 7月  16 03:39 hahah.txt
[root@localhost ~]# cp /opt/test/a/* /opt/test/
[root@localhost ~]# ls /opt/test/
a  hahah.txt
 

16. 创建⽬录/opt/test0

[root@localhost ~]# mkdir /opt/test0
[root@localhost ~]# ls /opt/
b.txt  c.txt  d0  d.txt  e.txt  test  test0  xxx.txt  yyy.txt
 

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.0050741 秒,1.0 GB/秒
[root@localhost ~]# dd if=/dev/zero of=/opt/test0/b.mp4 bs=20M count=1
记录了1+0 的读入
记录了1+0 的写出
20971520字节(21 MB)已复制,0.0232379 秒,902 MB/秒
[root@localhost ~]# dd if=/dev/zero of=/opt/test0/c.mp4 bs=80M count=1
记录了1+0 的读入
记录了1+0 的写出
83886080字节(84 MB)已复制,0.648783 秒,129 MB/秒
 

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

[root@localhost ~]# mkdir /opt/test0/b
[root@localhost ~]# ls /opt/test0/
a.mp4  b  b.mp4  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
 

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

[root@localhost ~]# find /opt/test0 -size +20M 
/opt/test0/c.mp4
[root@localhost ~]# find /opt/test0 -size +20M -exec rm -rf {} \;
[root@localhost ~]# find /opt/test0 -size +20M 
 

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

[root@localhost ~]# find /opt/test0 -size -20M 
/opt/test0
/opt/test0/a.mp4
/opt/test0/b
/opt/test0/b/a.mp4
/opt/test0/b/b.mp4
/opt/test0/b/c.mp4
[root@localhost ~]# find /opt/test0 -size -20M -exec rm -rf {} \;
 

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

[root@localhost ~]# find /opt/test0 -size 20M 
/opt/test0/b.mp4
[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/

[root@localhost ~]# ls /opt/test0

a.mp4 b b.mp4 c.mp4

24. 打开新的虚拟主机

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

[root@localhost  ~]# 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

 [root@localhost ~]# ls /opt bak.tar.gz 

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

[root@localhost  ~]# 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@localhost ~]# crontab -e
0 0 * * 3 tar -czf /tmp/yum_repos_$(date +\%Y\%m\%d\%H\%M\%S).tar.gz /etc/yum.repos.d/*.repo

[root@localhost~]# ls /tmp

repo_20240715195501.tar.gz

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值