RECSA 课后练习

1、创建文件命令练习:
(1) 在/目录下创建一个临时目录test;
(2)在临时目录test下创建五个文件,文件名分别为passwd,group,bashrc,profile,
sshd_config;
(3)在/test创建/etc/motd的软链接,文件名为motd.soft;创建/etc/motd的硬链接为motd.hard

mkdir test
 cd test/
touch {passwd,group,bashrc,profile,sshd_config}
ln -s /etc/motd motd.soft
ln  /etc/motd motd.hard

 2、重定向练习:
(1)将系统内核版本信息,发行版本信息,写入到/test/motd.soft文件中
(2)将当前主机主机名,当前用户使用的shell信息追加到/test/motd.hard文件中
(3)将根目录下的文件的文件名写入/test/file文件中
(4)查看当前工作目录是否为/test目录,将当前工作目录的详细信息追加到/test/file文件中

uname -srm >> /test/motd.soft
who am i >> /test/motd.hard 
cat /etc/shells >> /test/motd.hard 
ls / >> /test/file
 ll >> /test/file 

3、tee命令练习:
(1)将当前时间添加至/test目录下的passwd,group,bashrc,profile,sshd_config文件中
(2)将当前用户的用户名追加至/test目录下的passwd,group,bashrc,profile,sshd_config文件中

echo $(date ) | tee test/passwd
 echo $(date )  | tee  test/group
 echo $(date )  | tee  test/bashrc 
  echo $(date )  | tee  test/profile 
  echo $(date )  | tee  test/sshd_config 

echo $(who am i) | tee -a test/passwd
 echo $(who am i) | tee -a   test/group 
echo $(who am i) | tee -a   test/bashrc 
echo $(who am i) | tee -a  test/profile 
echo $(who am i) | tee -a   test/sshd_config 

4、vim命令练习:
(1)将/etc/passwd文件内容读入/test/passwd,并修改文件里的root字符为admin
(2)将/etc/group文件内容读入/test/group,只保留root开头的行内容
(3)将/root/.bashrc文件内容读入/test/bashrc,删除#号开头的行内容 

(4)将/etc/ssh/sshd_config文件内容读入/test/sshd_config,在该文件的第17行后添加一行内容
Port 22
(5)将/test/sshd_config文件中的第40-50行的yes改为no
(6)将/test/sshd_config文件另存为/test/sshd.conf
(7)将/test目录下的passwd,group,bashrc文件中的第一行内容复制至文档最后一行
(8)将/test目录下的profile,sshd_config文件中前两行内容复制至文档倒数第二行

(1)将/etc/passwd文件内容读入/test/passwd,并修改文件里的root字符为admin

vim /test/passwd
:r /etc/passwd
:%s/root/admin/g
:wq

(2)将/etc/group文件内容读入/test/group,只保留root开头的行内容

vim /test/group
:r /etc/group
:v/^root/d

 (3)将/root/.bashrc文件内容读入/test/bashrc,删除#号开头的行内容

vim /test/bashrc
:r /root/.bashrc
:^# d

 

 

(4)将/etc/ssh/sshd_config文件内容读入/test/sshd_config,在该文件的第17行后添加一行内容Port 22

vim /test/sshd_config
:r /etc/ssh/sshd_config
:set nu

 

 

(5)将/test/sshd_config文件中的第40-50行的yes改为no

40,50 s/yes/no

 

(6)将/test/sshd_config文件另存为/test/sshd.conf

:w /test/sshd.conf

(7)将/test目录下的passwd,group,bashrc文件中的第一行内容复制至文档最后一行

gg yy
G p

(8)将/test目录下的profile,sshd_config文件中前两行内容复制至文档倒数第二行

gg
2 yy
 

 

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值