RHCSA作业(1)

1. 文件管理命令练习:
在/opt目录下创建一个临时目录tmp;
在临时目录下创建一个文件,文件名为a.txt;
 将a.txt复制成b.txt;
 将b.txt改名成为c.txt;
 创建符号链接,链接文件名为linkc.txt;

[root@server ~]# mkdir /opt/tmp
[root@server ~]# ll /opt
total 0
drwxr-xr-x. 2 root root 6 May 14 22:49 tmp
[root@server ~]# cd tmp
-bash: cd: tmp: No such file or directory
[root@server ~]# cd /opt/tmp
[root@server tmp]# touch a.txt
[root@server tmp]# ll
total 0
-rw-r--r--. 1 root root 0 May 14 22:51 a.txt
 
[root@server tmp]# cp a.txt b.txt
[root@server tmp]# ll -i
total 0
35393576 -rw-r--r--. 1 root root 0 May 14 22:51 a.txt
35393579 -rw-r--r--. 1 root root 0 May 14 23:03 b.txt
[root@server tmp]# mv b.txt c.txt
[root@server tmp]# ll -i
total 0
35393576 -rw-r--r--. 1 root root 0 May 14 22:51 a.txt
35393579 -rw-r--r--. 1 root root 0 May 14 23:03 c.txt

[root@server tmp]# ln -s c.txt linkc.txt
[root@server tmp]# ll -i
total 0
35393576 -rw-r--r--. 1 root root 0 May 14 22:51 a.txt
35393579 -rw-r--r--. 1 root root 0 May 14 23:03 c.txt
35393580 lrwxrwxrwx. 1 root root 5 May 14 23:05 linkc.txt -> c.txt


2.  将echo "123"结果重定向到info.txt, 将test11111结果重定向到info.txt
    使用多种方式完成

[root@server tmp]# echo "123" > info.txt
[root@server tmp]# ll -i
total 4
35393576 -rw-r--r--. 1 root root 0 May 14 22:51 a.txt
35393579 -rw-r--r--. 1 root root 0 May 14 23:03 c.txt
35393581 -rw-r--r--. 1 root root 4 May 14 23:06 info.txt
35393580 lrwxrwxrwx. 1 root root 5 May 14 23:05 linkc.txt -> c.txt
[root@server tmp]# cat info.txt 
123
[root@server tmp]# echo test11111 > info.txt 
[root@server tmp]# cat info.txt 
test11111


[root@server tmp]# echo "123" >> info.txt 
[root@server tmp]# echo test1111 >> info.txt 
[root@server tmp]# cat info.txt 
test11111
123
test1111


3.    vi练习:完成如下步骤
1) 应用vi命令在/tmp文件夹下创建文件,文件名newfile。在newfile首行输入日期时间
2) 将/boot/grub2/grub.cfg文档的内容读入到newfile文档中(在日期的下一行即第2行)
3) 查找文档中包含#号字符的行,将整行删除
4) 开启VI的行号提示功能
5) 将光标移动到第5行,并在第5行后产生一新的空白行第6行
6) 修改内容。将所有的timeout=5,更改为time=30
7) 将整个文档中的所有root字符更改为admin字符
8) 复制第1行的日期时间内容到文档末
9)将文档保存,将文档再次另存为/boot/newfile2,退出VI编辑器

(1)在终端中,输入“vim newfile/vi newfile”创建newfile文件(因为此处已经用cd命令切换至/opt/tmp目录,所以不用在写之前的路径),进入vi编辑模式输入日期后,在末行模式下“wq”保存退出即可

[root@server tmp]# vi newfile
[root@server tmp]# cat newfile 
2023-05-14 23:09

 (2)先在命令模式中输入小写字母o跳转至第二行,在末行模式中,输入“:r /boot/grub2/grub.cfg”以读取指定文件内容

(3)末行模式中,输入“:g/#/d”查找#字符的行并整行删除

 (4)在末行模式中,输入“:set nu”显示行号

(5) 在命令模式下输入:5G跳转至第五行,然后输入小写字母o,调转至第六行并插入

 (6)在末行模式下输入:%s /timeout =5/time=30/g 进行字符串替换

 

 (7)与(6)操作一致

(8)在命令模式下,输入 gg 将光符挪至文章首字符,再输入 yy 复制第一行内容,输入 G 挪至文章尾字符,最后输入 p 粘贴复制内容

 (9)在末行模式下,输入“:w”进行保存然后输入“:w /boot/newfile2”另存到指定路径文件此时会在/boot目录下创建一个新文件newfile2

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值