课后习题
1、目录操作
1)创建目录test
创建前先查看是否存在 “test” 目录
[root@rhcsa ~]# mkdir -p /root/test
[root@rhcsa ~]# ls
2)使用两种方式在test目录中创建文本文件text1.txt, text2.txt
[root@rhcsa ~]# vim test/text.txt
[root@rhcsa ~]# touch test/text2.txt
[root@rhcsa test]# mv text.txt text1.txt
[root@rhcsa test]# ls
!突然发现未按照题目要求命名,故将 text.txt 重命名为 text1.txt
[root@rhcsa test]# mv text.txt text1.txt
[root@rhcsa test]# ls
3)使用Vim在文件text1.txt中写入
Welcome to my Linux.
You are the best.
This is my first file to create on linux
[root@rhcsa test]# vim text1.txt
Welcome to my Linux.
You are the best.
This is my first file to create on linux.
esc + :wq + enter 保存并退出
4)设置行号,并将文本中my替换成your,将文件另存为new_test1.txt
[root@rhcsa test]# vim text1.txt
:set number
enter 查看结果
:1,$s/my/you/g
enter 查看结果
将文件另存为new_test1.txt
:1,3 w /root/test/new_test.txt
5)将test中的文件拷贝到test2目录
[root@rhcsa ~]# cp -r test test2
6)将test2目录中的test1.txt重命名为test111.txt
[root@rhcsa test2]# mv text1.txt text111.txt
7)在test2目录中新建test111.txt的软链接文件 test111_symb.txt
[root@rhcsa test2]# ln -s text111.txt test111_soft.txt
8)在test2目录中新建test111.txt的硬链接文件 test111_hard.txt
[root@rhcsa test2]# ln text111.txt test111_hard.txt
9)删除test目录中test1.txt
[root@rhcsa test]# rm -f text1.txt
10)删除test目录
[root@rhcsa ~]# rm -rf test
2、将echo "This is my first time to use pipe"内容输出到屏幕上,且保存到pipe_data.txt中
[root@rhcsa ~]# echo "This is my first time to use pipe" | tee pipe_data.txt
3.文件内容浏览
1)cat查看/etc/passwd文件内容,且输出时带行号
[root@rhcsa ~]# cat -n /etc/passwd
2)使用more/less查看/etc/passwd内容,且每页显示10行
[root@rhcsa ~]# more -10 /etc/passwd
3)使用head/tail分别查看文件前5行内容和后5行内容
[root@rhcsa ~]# head -5 /etc/passwd
[root@rhcsa ~]# tail -5 /etc/passwd