1. 使⽤ls查看/etc/⽬录下所有的⽂件信息
[root@web1 ~]# ls /etc/
2. 使⽤ls查看/etc/⽬录下名包含“a”字⺟的⽂件或者⽬录信息
[root@web1 ~]# ls /etc/ | grep 'a'
3. 使⽤ls查看/etc/⽬录下以".conf"结尾的⽂件信息
[root@web1 ~]# ls /etc | grep '\.conf$'
4. 使⽤ls查看/etc/⽬录中以"y"字⺟开头的⽂件信息
[root@web1 ~]# ls /etc | grep '^y'
5. find查找/var/⽬录中以“.log”⽂件
[root@web1 ~]# find /var/ -name "*.log*" -type f
6. 在opt⽬录下创建test⽬录
[root@web1 ~]# mkdir /opt/test
[root@web1 ~]# ls /opt/
aaa.mp4 a.txt b.txt c.txt haha.txt test
7. 在test⽬录中创建abc.txt,def.txt.ghi.txt,xxx.txt.yyy.txt五个⽂件
[root@web1 ~]# cd /opt/test/
[root@web1 test]# touch abc.txt def.txt ghi.txt xxx.txt yyy.txt
[root@web1 test]# ls
abc.txt def.txt ghi.txt xxx.txt yyy.txt
8. 修改以上5个⽂件的最后修改时间分别为15,14,13,12,11,10⽇
[root@web1 test]# touch abc.txt -m -d "2024-07-15"
[root@web1 test]# touch def.txt -m -d "2024-07-14"
[root@web1 test]# touch ghi.txt -m -d "2024-07-13"
[root@web1 test]# touch xxx.txt -m -d "2024-07-12"
[root@web1 test]# touch yyy.txt -m -d "2024-07-11"
[root@web1 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@web1 test]# mkdir a
[root@web1 test]# ls
a abc.txt def.txt ghi.txt xxx.txt yyy.txt
10. 将以上5个⽂件复制⼀份到a⽬录中
[root@web1 test]# cp abc.txt a
[root@web1 test]# ls a
abc.txt
[root@web1 test]# cp def.txt ghi.txt xxx.txt yyy.txt a
[root@web1 test]# ls a
abc.txt def.txt ghi.txt xxx.txt yyy.txt
11. 将a⽬录⽂件做成bak.tar.gz⽂件保存到家⽬录中
[root@web1 test]# tar -zcvf /home/bak.tar.gz a/
a/
a/abc.txt
a/def.txt
a/ghi.txt
a/xxx.txt
a/yyy.txt
[root@web1 test]# ls /home/
bak.tar.gz q user4
12. 使⽤find删除test⽬录下3天前的⽂件
[root@web1 ~]# find /opt/test/ -mtime +3 -exec rm -rf {} \;
[root@web1 ~]# ls /opt/test/
a abc.txt def.txt
13. find删除opt⽬录下3天内的⽂件
[root@web1 test]# find /opt -mtime -3 -type f -exec rm -rf {} \;
14. find删除正好第三天的⽂件
[root@web1 test]# find /opt -mtime 3
/opt/test/ghi.txt
[root@web1 test]# cd
[root@web1 ~]# find /opt -mtime 3 -exec rm -rf {} \;
[root@web1 ~]# ls /opt/
test
15. 将/opt/test/a⽬录中的⽂件复制⼀份到/opt/test/⽬录下
[root@web1 ~]# cp /opt/test/a/* /opt/test/
[root@web1 ~]# ls /opt/test/
a abc.txt def.txt ghi.txt xxx.txt yyy.txt
16. 创建⽬录/opt/test0
[root@web1 ~]# mkdir /opt/test0
[root@web1 ~]# ls /opt/
test test0
17. 在/opt/test0/⽬录中创建三个⽂件 a.mp4(5M),b.mp4(20M),c.mp4(80M)
[root@web1 ~]# dd if=/dev/zero of=/opt/test0/a.mp4 bs=5M count=1
[root@web1 ~]# dd if=/dev/zero of=/opt/test0/b.mp4 bs=20M count=1
[root@web1 ~]# dd if=/dev/zero of=/opt/test0/c.mp4 bs=80M count=1
[root@web1 ~]# ls /opt/test0
a.mp4 b.mp4 c.mp4
18. 创建⽬录/opt/test0/b/
[root@web1 ~]# mkdir /opt/test0/b/
[root@web1 ~]# ls /opt/test0
a.mp4 b b.mp4 c.mp4
19.将/opt/test0/中的⽂件复制⼀份/opt/test0/b/⽬录中
[root@web1 ~]# cp /opt/test0/* /opt/test0/b/
[root@web1 ~]# ls /opt/test0/b
a.mp4 b.mp4 c.mp4
20. find查询/opt/test0/⽬录中⽂件⼤于20M的,并删除
[root@web1 ~]# find /opt/test0/ -size +20M -exec rm -rf {} \;
[root@web1 ~]# find /opt/test0/ -size +20M
21. find查询/opt/test0/⽬录中⽂件⼩于20M的⽂件并删除
[root@web1 ~]# find f /opt/test0/ -size -20M -type f -exec rm -rf {} \;
[root@web1 ~]# ls /opt/test0/
b b.mp4
22. find查找/opt/test0/⽬录中⽂件size为20M的⽂件并删除
[root@web1 ~]# find /opt/test0/ -size 20M -exec rm -rf {} \;
[root@web1 ~]# find /opt/test0/ -size 20M
23. /opt/test0/b中的⽂件复制⼀份到/opt/test0中
[root@web1 ~]# cp /opt/test0/b/* /opt/test0/
24. 打开新的虚拟主机
打开vm,克隆,打开新主机
25. 将家⽬录中的bak.tar.gz⽂件上传到新主机的/opt⽬录中
[root@web1 ~]# scp /home/bak.tar.gz root@192.168.1.20:/opt/
root@192.168.1.20's password:
bak.tar.gz 100% 181 207.6KB/s 00:00
新主机:
[root@localhost ~]# ls /opt/
bak.tar.gz
26. 将新主机的/etc/skel/⽬录下载到当前主机的/opt⽬录中
[root@web1 ~]# scp -r root@192.168.1.20:/etc/skel /opt
root@192.168.1.20's password:
.bash_logout 100% 18 9.9KB/s 00:00
.bash_profile 100% 193 133.1KB/s 00:00
.bashrc 100% 231 358.4KB/s 00:00
[root@web1 ~]# ls /opt/
skel test test0
27. 设置计划任务,每周3将/etc/yum.repos.d/⽬录下的.repo⽂件压缩保存到tmp,在⽂件名中添加时间戳
[root@web1 ~]# crontab -e
0 0 * * 3 tar -cvzf /tmp/yum.repos.d_$(date "+\%Y\%m\%d\%H\%M\%S").tar.gz /etc/yum.repos.d/*.repo
[root@web1 ~]# crontab -l
07-11
990
07-14
138
07-13
1100
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交