1. 使⽤ls查看/etc/⽬录下所有的⽂件信息
[root@localhost ~]# ls -l /etc/
2. 使⽤ls查看/etc/⽬录下名包含“a”字⺟的⽂件或者⽬录信息
[root@localhost ~]# ls -l /etc/*a*
3. 使⽤ls查看/etc/⽬录下以".conf"结尾的⽂件信息
[root@localhost ~]# ls -l /etc/*.conf
4. 使⽤ls查看/etc/⽬录中以"y"字⺟开头的⽂件信息
[root@localhost ~]# ls -l /etc/y*/
5. find查找/var/⽬录中以“.log”⽂件
[root@localhost ~]# find / -name "*.log" -type f
6. 在opt⽬录下创建test⽬录
[root@localhost ~]# mkdir /opt/test/
您在 /var/spool/mail/root 中有新邮件
[root@localhost ~]# ls /opt/
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 /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 ~]# stat /opt/test/abc.txt/
文件:"/opt/test/abc.txt/"
大小:6 块:0 IO 块:4096 目录
设备:fd00h/64768d Inode:2796087 硬链接:2
权限:(0755/drwxr-xr-x) Uid:( 0/ root) Gid:( 0/ root)
环境:unconfined_u:object_r:usr_t:s0
最近访问:2024-07-15 22:02:43.511362706 +0800
最近更改:2024-07-15 00:00:00.000000000 +0800
最近改动:2024-07-15 22:05:46.348367349 +0800
创建时间:-
[root@localhost ~]# stat /opt/test/def.txt/
文件:"/opt/test/def.txt/"
大小:6 块:0 IO 块:4096 目录
设备:fd00h/64768d Inode:18261864 硬链接:2
权限:(0755/drwxr-xr-x) Uid:( 0/ root) Gid:( 0/ root)
环境:unconfined_u:object_r:usr_t:s0
最近访问:2024-07-15 21:59:20.657357555 +0800
最近更改:2024-07-14 00:00:00.000000000 +0800
最近改动:2024-07-15 22:05:58.886367667 +0800
创建时间:-
[root@localhost ~]# stat /opt/test/ghi.txt/
文件:"/opt/test/ghi.txt/"
大小:6 块:0 IO 块:4096 目录
设备:fd00h/64768d Inode:33748343 硬链接:2
权限:(0755/drwxr-xr-x) Uid:( 0/ root) Gid:( 0/ root)
环境:unconfined_u:object_r:usr_t:s0
最近访问:2024-07-15 21:59:29.905357790 +0800
最近更改:2024-07-13 00:00:00.000000000 +0800
最近改动:2024-07-15 22:06:08.490367911 +0800
创建时间:-
您在 /var/spool/mail/root 中有新邮件
[root@localhost ~]# stat /opt/test/xxx.txt/
文件:"/opt/test/xxx.txt/"
大小:6 块:0 IO 块:4096 目录
设备:fd00h/64768d Inode:52801190 硬链接:2
权限:(0755/drwxr-xr-x) Uid:( 0/ root) Gid:( 0/ root)
环境:unconfined_u:object_r:usr_t:s0
最近访问:2024-07-15 21:59:35.258357926 +0800
最近更改:2024-07-12 00:00:00.000000000 +0800
最近改动:2024-07-15 22:06:18.059368154 +0800
创建时间:-
[root@localhost ~]# stat /opt/test/yyy.txt/
文件:"/opt/test/yyy.txt/"
大小:6 块:0 IO 块:4096 目录
设备:fd00h/64768d Inode:2796088 硬链接:2
权限:(0755/drwxr-xr-x) Uid:( 0/ root) Gid:( 0/ root)
环境:unconfined_u:object_r:usr_t:s0
最近访问:2024-07-15 21:59:42.249358104 +0800
最近更改:2024-07-11 00:00:00.000000000 +0800
最近改动:2024-07-15 22:06:41.240368742 +0800
创建时间:-
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 -r /opt/test/* /opt/test/a
或者:
[root@localhost ~]# cp /opt/test/abc.txt /opt/test/a
您在 /var/spool/mail/root 中有新邮件
[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 -zcvf /home/bak.tar.gz /opt/test/a
[root@localhost ~]# ls /home/bak.tar.gz
/home/bak.tar.gz
12. 使⽤find删除test⽬录下3天前的⽂件
[root@localhost ~]# find /opt/test/ -mtime +3|xargs rm -rf
13. find删除opt⽬录下3天内的⽂件
[root@localhost ~]# find /opt/ -mtime -3|xargs rm -rf
14. find删除正好第三天的⽂件
[root@localhost ~]# find / -mtime 3|xargs rm -rf
15. 将/opt/test/a⽬录中的⽂件复制i⼀份到/opt/test/⽬录下
[root@localhost ~]# cp -r /opt/test/a/* /opt/test/
或者:
[root@localhost ~]# cp -r /opt/test/a/abc.txt /opt/test/
[root@localhost ~]# cp -r /opt/test/a/def.txt /opt/test/
[root@localhost ~]# cp -r /opt/test/a/ghi.txt /opt/test/
[root@localhost ~]# cp -r /opt/test/a/xxx.txt /opt/test/
[root@localhost ~]# cp -r /opt/test/a/yyy.txt /opt/test/
16. 创建⽬录/opt/test0
[root@localhost ~]# mkdir /opt/test0
[root@localhost ~]# ls /opt/
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.00471946 秒,1.1 GB/秒
[root@localhost ~]# dd if=/dev/zero of=/opt/test0/b.mp4 bs=20M count=1
记录了1+0 的读入
记录了1+0 的写出
20971520字节(21 MB)已复制,0.0488267 秒,430 MB/秒
[root@localhost ~]# dd if=/dev/zero of=/opt/test0/c.mp4 bs=80M count=1
记录了1+0 的读入
记录了1+0 的写出
83886080字节(84 MB)已复制,0.296791 秒,283 MB/秒
18. 创建⽬录/opt/test0/b/
[root@localhost ~]# mkdir /opt/test0/b/
[root@localhost ~]# ls /opt/test0/
b
19. 将/op t/test0/中的⽂件复制⼀份/opt/test0/b/⽬录中
[root@localhost ~]# cp -r /opt/test0/a.mp4 /opt/test0/b/
[root@localhost ~]# cp -r /opt/test0/b.mp4 /opt/test0/b/
[root@localhost ~]# cp -r /opt/test0/c.mp4 /opt/test0/b/
20. find查询/opt/test0/⽬录中⽂件⼤于20M的,并删除
1)[root@localhost ~]# find /opt/test0/ -size +20M -exec rm -rf {} \;
2)[root@localhost ~]# find /opt/test0/ -size +20M | xargs rm -rf
21. find查询/opt/test0/⽬录中⽂件⼩于20M的⽂件并删除
1)[root@localhost ~]# find /opt/test0/ -size -20M -exec rm -rf {} \;
2)[root@localhost ~]# find /opt/test0/ -size -20M | xargs rm -rf
22. find查找/opt/test0/⽬录中⽂件size为20M的⽂件并删除
1)[root@localhost ~]# find /opt/test0/ -size 20M -exec rm -rf {} \;
2)[root@localhost ~]# find /opt/test0/ -size 20M | xargs rm -rf
23. /opt/test0/b中的⽂件复制⼀份到/opt/test0中
[root@localhost ~]# cp -r /opt/test0/b/ /opt/test0/
24. 打开新的虚拟主机
新机IP地址:192.168.204.3
旧机IP地址:192.168.204.2
25. 将家⽬录中的bak.tar.gz⽂件上传到新主机的/opt⽬录中
[root@localhost ~]# scp /home/bak.tar.gz root@192.168.204.3:/opt/
26. 将新主机的/e tc/skel/⽬录下载到 当前主机的/opt⽬录中
[root@localhost ~]# scp root@192.168.204.3:/etc/skel/ /opt/
27. 设置计划任务,每周3将/e tc/yum.repos.d/⽬录下的.repo⽂件压缩保存到tmp,在⽂件
名中添加时间戳
[root@localhost ~]# whereis tar
tar: /usr/bin/tar /usr/share/man/man1/tar.1.gz /usr/share/man/man5/tar.5.gz
[root@localhost ~]# crontab -e
[root@localhost ~]# ls /tmp/(下图为每一分钟测试图)