linux命令练习

1.创建文件命令练习

(1)在/目录下创建一个临时目录test

[root@tianqinwei /]# ls
bin   d    dir123  home  lib64  mnt  proc  run   srv  tmp  var
boot  dev  etc     lib   media  opt  root  sbin  sys  usr
[root@tianqinwei /]# mkdir test
[root@tianqinwei /]# ls
bin   d    dir123  home  lib64  mnt  proc  run   srv  test  usr
boot  dev  etc     lib   media  opt  root  sbin  sys  tmp   var

(2)在临时目录下创建5个文件,文件名分别为passwd,group,bashrc,profile,sshd_config

[root@tianqinwei /]# cd test
[root@tianqinwei test]# touch passwd group bashrc profile sshd_config
[root@tianqinwei test]# ls
bashrc  group  passwd  profile  sshd_config
[root@tianqinwei test]# 

(3)在/test创建/etc/motd的软链接,文件名为motd.soft;创建/etc/motd的硬链接为motd.hard

[root@tianqinwei test]# ln -s /etc/motd motd.soft
[root@tianqinwei test]# ln /etc/motd motd.hard
[root@tianqinwei test]# ls
bashrc  group  motd.hard  motd.soft  passwd  profile  sshd_config
[root@tianqinwei test]# 

2.重定向练习

(1)将系统内核版本信息,发行版本信息,写入到/test/motd.soft文件中

[root@tianqinwei test]# cat /etc/redhat-release > motd.soft
[root@tianqinwei test]# uname -r >> motd.soft
[root@tianqinwei test]# cat motd.soft
Red Hat Enterprise Linux release 8.0 (Ootpa)
4.18.0-80.el8.x86_64
[root@tianqinwei test]# 

(2)将当前主机主机名,当前用户使用的shell信息追加到/test/motd.hard文件中

[root@tianqinwei test]# cat /etc/hostname > motd.hard
[root@tianqinwei test]# echo $SHELL >> motd.hard
[root@tianqinwei test]# cat motd.hard
tianqinwei
/bin/bash
[root@tianqinwei test]# 

(3)将根目录下的文件的文件名写入/test/file文件中

[root@tianqinwei test]# ls / > /test/file
[root@tianqinwei test]# cat file
bin
boot
d
dev
dir123
etc
home
lib
lib64
media
mnt
opt
proc
root
run
sbin
srv
sys
test
tmp
usr
var
[root@tianqinwei test]# 

(4)查看当前工作目录是否为/test目录,将当前工作目录的详细信息追加到/test/file文件中

[root@tianqinwei test]# pwd
/test
[root@tianqinwei test]# pwd >> /test/file
[root@tianqinwei test]# cat file
bin
boot
d
dev
dir123
.
.
.
usr
var
/test
[root@tianqinwei test]# 

3.tee命令练习

(1)将当前时间添加至/test目录下的passwd,group,bashrc,profile,sshd_config文件中

[root@tianqinwei ~]# date | tee passwd group bashrc profile sshd_config
Mon Feb 20 21:54:46 CST 2023
[root@tianqinwei ~]# cat passwd
Mon Feb 20 21:54:46 CST 2023
[root@tianqinwei ~]# cat group
Mon Feb 20 21:54:46 CST 2023
[root@tianqinwei ~]# cat bashrc
Mon Feb 20 21:54:46 CST 2023
[root@tianqinwei ~]# cat profile
Mon Feb 20 21:54:46 CST 2023
[root@tianqinwei ~]# cat sshd_config
Mon Feb 20 21:54:46 CST 2023
[root@tianqinwei ~]# 

(2)将当前用户的用户名追加至/test目录下的passwd,group,bashrc,profile,sshd_config文件中

[root@tianqinwei ~]# cat /etc/hostname | tee -a passwd group bashrc profile sshd_config
tianqinwei
[root@tianqinwei ~]# cat passwd
Mon Feb 20 21:54:46 CST 2023
tianqinwei
[root@tianqinwei ~]# cat group
Mon Feb 20 21:54:46 CST 2023
tianqinwei
[root@tianqinwei ~]# cat bashrc
Mon Feb 20 21:54:46 CST 2023
tianqinwei
[root@tianqinwei ~]# cat profile
Mon Feb 20 21:54:46 CST 2023
tianqinwei
[root@tianqinwei ~]# cat sshd_config
Mon Feb 20 21:54:46 CST 2023
tianqinwei
[root@tianqinwei ~]# 

4.vim命令练习

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

[root@tianqinwei /]# cd test
[root@tianqinwei test]# cp /etc/passwd /test/passwd 
cp: overwrite '/test/passwd'? y
[root@tianqinwei test]# vim passwd

之后在末行模式中输入“:%s/root/admin/g”替换所有的root为admin

输入“ :wq”退出vim。后再查看passwd文件中的内容

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

[root@tianqinwei test]# cp /etc/group /test/group
cp: overwrite '/test/group'? y
[root@tianqinwei test]# vim group

之后在命令模式中将光标移至第二行的开端,输入“dG”并":wq"保存退出

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

之后将光标移至#开头的所在行输入“dd”清空所在行,保存退出

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

[root@tianqinwei test]# cp /etc/ssh/sshd_config /test/sshd_config
cp: overwrite '/test/sshd_config'? y
[root@tianqinwei test]# vim sshd_config

输入”:set nu”打开行号显示,进入编辑模式输入指定内容

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

[root@tianqinwei test]# vim /test/sshd_config

之后输入“:40,50 s/yes/no/g”替换

(6)将/test/sshd_config文件另存为/test/sshd_conf

末行模式输入“:w /test/sshd_conf”

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

输入”:set nu”打开行号显示,在三个文件中分别输入“:1 co +最后一行行号”

<1>passwd


<2>group


<3>bashrc


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

输入”:set nu”打开行号显示,在两个文件中分别输入“:1 co +最后一行行号”

<1>profile


<2>sshd_config


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

雨天_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值