RHCSA练习

本文详细介绍了Linux命令行中重定向操作,如输出重定向、错误重定向、追加、管道等,并配合vim编辑器进行文件操作,包括复制、替换、删除和移动行内容等。
摘要由CSDN通过智能技术生成

一、作业题目

一.重定向练习题

1. 将命令(比如,ls )的标准输出重定向到文件`output.txt`。 
[root@root ~]# ls > output.txt
2. 将命令(比如,ls /aaa)的标准错误重定向到文件`error.txt`。 
[root@root ~]#  ls /aaa 2> error.txt
3. 将命令 (比如,ls ~ /aaa)的标准输出和标准错误都重定向到文件`output_and_error.txt`。
[root@root ~]# ls ~ /aaa > output_and_error.txt 2>&1
4. 将命令(比如,ls /aaa)的输出追加到文件`output.txt`(而不是覆盖文件)。 
[root@root ~]# ls /aaa >> output.txt
5. 将文件`input.txt`作为cat的标准输入。 
[root@root ~]# cat < input.txt
6. 将命令1的执行结果通过管道符传递给命令2。 
[root@root ~]# ls | grep "a"
7. 将ls的输出同时显示在终端和保存到文件`output.txt`。
[root@root ~]# ls | tee output.txt
8. 将ls的输出重定向到`/dev/null`,以丢弃输出。 
[root@root ~]# ls > /dev/null
9. 将两个文件合并输出到一个新文件里面(cat命令)
[root@root ~]# cat file1.txt file2.txt >> output.txt
10. 创建三个文件,内容随意,将这三个文件的内容显示在屏幕上并且合并为一个新的文件。
#创建三个文件
[root@root ~]# echo "Content of file1" > file1.txt
[root@root ~]# echo "Content of file2" > file2.txt
[root@root ~]# echo "Content of file3" > file3.txt

#将三个文件内容显示到屏幕上
[root@root ~]# cat file1.txt file2.txt file3.txt

#将三个文件内容合并为一个新文件
[root@root ~]# cat file1.txt file2.txt file3.txt > merged.txt

二.vim练习题

1. 将/etc/passwd复制到当前用户的家目录(以下的操作都是对~/passwd进行编辑)
[root@root ~]# cp /etc/passwd ~/passwd
[root@root ~]# vim ~/passwd
2. 将第一行中的root全部替换为toor
:1s/root/toor/g
3. 替换1-10行所有的冒号为分号
:1,10s/:/;/g
4. 全文替换x为z
:%s/x/z/g
5. 将光标移动到第10行删除之后的2行
:10, +2d
6. 删除10行-20行的内容
:10,20d
7. 复制第10-20的内容并粘贴到20行之后
:10,20t20
8. 删除第2行的第1个冒号后面的内容
:2s/:.*//
9. 删除第3行的第一个冒号前面的内容
:3s/.*:/:/

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值