1、创建文件命令练习:
(1) 在/目录下创建一个临时目录test;
(2)在临时目录test下创建五个文件,文件名分别为passwd,group,bashrc,profile,
sshd_config;
(3)在/test创建/etc/motd的软链接,文件名为motd.soft;创建/etc/motd的硬链接为motd.hard
(1)、创建test目录: [root@server ~]# mkdir /test (2)、在test目录下创建文件passwd,group,bashrc,profile: [root@server ~]# touch /test/{passwd,group,bashrc,profile,sshd_config} (3)、在test目录下创建/etc/motd的软连接motd.soft: [root@server ~]# ln -s /etc/motd /test/motd.soft (4)、在test目录下创建/etc/motd的硬链接motd.hard: [root@server ~]# ln /etc/motd /test/motd.hard (5)、查看是否创建完成: [root@server ~]# ll /test
2、重定向练习:
(1)将系统内核版本信息,发行版本信息,写入到/test/motd.soft文件中
(2)将当前主机主机名,当前用户使用的shell信息追加到/test/motd.hard文件中
(3)将根目录下的文件的文件名写入/test/file文件中
(4)查看当前工作目录是否为/test目录,将当前工作目录的详细信息追加到/test/file文件中
(1)、将发行版本信息写入/test/motd.soft中: [root@server ~]# cat /etc/redhat-release > /test/motd.soft 将系统内核版本信息写入/test/motd.soft中: [root@server ~]# uname -r >> /test/motd.soft 查看信息写入情况: [root@server ~]# cat /test/motd.soft Red Hat Enterprise Linux release 8.5 (Ootpa) 4.18.0-348.el8.x86_64
(2)、将当前主机名写入/test/motd.hard中:
[root@server ~]# cat /etc/hostname >> /test/motd.hard将当前用户使用的hell信息追加到/test/motd.hard中:
[root@server ~]# echo $SHELL >> /test/motd.hard查看写入情况:
[root@server ~]# cat /test/motd.hard
Red Hat Enterprise Linux release 8.5 (Ootpa)
4.18.0-348.el8.x86_64
server
/bin/bash
(3)、将根目录下的文件的文件名写入/test/file文件中:
[root@server ~]# ls / > /test/file查看写入情况:
[root@server ~]# cat /test/file
bin
boot
dev
etc
home
lib
lib64
media
mnt
opt
proc
root
run
sbin
srv
sys
test
tmp
usr
var
(4)、查看当前工作目录是否为/test目录:
[root@server ~]# ls -dl
dr-xr-x---. 16 root root 4096 Oct 21 16:21 .将当前工作目录的详细信息追加到/test/file文件中:
[root@server ~]# ls -dl >> /test/file查看写入情况:
[root@server ~]# cat /test/file
bin
boot
dev
etc
home
lib
lib64
media
mnt
opt
proc
root
run
sbin
srv
sys
test
tmp
usr
var
dr-xr-x---. 16 root root 4096 Oct 21 16:21 .
3、tee命令练习:
(1)将当前时间添加至/test目录下的passwd,group,bashrc,profile,sshd_config文件中
(2)将当前用户的用户名追加至/test目录下的passwd,group,bashrc,profile,sshd_config文件
中
(1)、将当前时间添加至/test目录下的passwd,group,bashrc,profile,sshd_config文件中: [root@server ~]# date | tee /test/{passwd,group,bashrc,profile,sshd_config} Fri Oct 21 17:31:35 CST 2022 查看写入情况: [root@server ~]# cat /test/{passwd,group,bashrc,profile,sshd_config} Fri Oct 21 17:31:35 CST 2022 Fri Oct 21 17:31:35 CST 2022 Fri Oct 21 17:31:35 CST 2022 Fri Oct 21 17:31:35 CST 2022 Fri Oct 21 17:31:35 CST 2022
(2)、将当前用户的用户名追加至/test目录下的passwd,group,bashrc,profile,sshd_config文件中:
[root@server ~]# cat /etc/hostname | tee -a /test/{passwd,group,bashrc,profile,sshd_config}
server查看写入情况:
[root@server ~]# cat /test/{passwd,group,bashrc,profile,sshd_config}
Fri Oct 21 17:31:35 CST 2022
server
Fri Oct 21 17:31:35 CST 2022
server
Fri Oct 21 17:31:35 CST 2022
server
Fri Oct 21 17:31:35 CST 2022
server
Fri Oct 21 17:31:35 CST 2022
server
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@server ~]# cat /etc/passwd > /test/passwd 进入vim命令模式: [root@server ~]# vim /test/passwd 更换root为admin操作命令: :% s/root/admin/g
root改为admin:
(2)、将/etc/group文件内容读入/test/group:
[root@server ~]# cat /etc/group > /test/group进入vim命令模式:
[root@server ~]# vim /test/group只保留root开头的行内容操作命令:
:v/root/d
保留root开头的行内容后:
(3)、将/root/.bashrc文件内容读入/test/bashrc:
[root@server ~]# cat /root/.bashrc > /test/bashrc进入vim命令模式:
[root@server ~]# vim /test/bashrc删除#号开头的行内容的操作命令:
:g/#/d
删除#开头的行后:
(4)、将/etc/ssh/sshd_config文件内容读入/test/sshd_config:
[root@server ~]# cat /etc/ssh/sshd_config >/test/sshd_config进入vim命令模式:
[root@server ~]# vim /test/sshd_config在该文件的第17行后添加一行内容Port 22,这里和17行一样,就直接复制了:
:17 co 17
添加一行Port 22后:
(5)、将/test/sshd_config文件中的第40-50行的yes改为no
:40,50 s/yes/no/g
40-50行yes改为no后:
(6)、将/test/sshd_config文件另存为/test/sshd.conf:
:w /test/sshd.conf
(7)、进入/test/passwd的vim界面:
[root@server ~]# vim /test/passwd分屏添加/test/group的vim界面:
:sp /test/group分屏添加/test/bashrc的vim界面:
:sp /test/bashrc按Ctrl+w w各个界面来回切换,后输入:set nu查看各个行的行数,输入:1 co n,n代表最后一行
(8)、进入/test/profile的vim界面:
[root@server ~]# vim /test/profile分屏添加/test/sshd_config的vim界面:
:sp /test/sshd_config按Ctrl+w w各个界面来回切换,后输入:set nu查看各个行的行数,输入:1,2 co n-1,n代表最后一行
总结:
喜欢的话点赞加关注哦,后续精彩教程小编会持续为大家更。ヾ(≧▽≦*)o