SHELL第一天——复习RHCSA

  • 1、创建文件命令练习:
  • 2、重定向练习:
  • 3、echo命令练习
  • 4、vim命令练习:
  • 5、文件内容查看:
  • 6、文本处理命令:
  • 7、复制、移动
  • 8、文件查找
  • 9、打包压缩
  • 10、创建mygroup组,group组,GID为600的temp组及组id为40000的adminuser组
  • 11、创建myuser用户属于mygroup组群,接着以myuser身份登录,创建ex和hv两个文件于/home/myuser目录,并使hv文件的同组用户是root。请依次写出相应执行的命令
  • 12、添加一新用户helen并设置其用户主目录/helen,密码为空,并将temp组群作为用户helen的附加组群。请依次写出相应执行的命令
  • 13、创建用户user,密码为“a1b2c3”,并将其加入group组群
  • 14、新建一个名为sarah的用户,不属于adminuser组,并将其shell设置为不可登陆shell
  • 15、创建alex用户,使alex用户满足以下要求:用户id为3456,描述名为alian,密码为glegunge,附属组为group
  • 16、创建 admin用户,无密码,描述为teshu,设置基本组为temp
  • 17、设置权限,要求如下:
  • 18、基本存储配置


1、创建文件命令练习:

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

[root@localhost ~]# mkdir test
[root@localhost ~]# cd test/
[root@localhost test]# touch {passwd,group,bashrc,profile,sshd_config}
[root@localhost test]# ln -s /etc/motd motd.soft
[root@localhost test]# ln  /etc/motd motd.hard

ota_from_target_files添加一个目录 在test目录下新建一个文件_bash

2、重定向练习:

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

[root@localhost ~]# uname -r >> test/motd.soft
[root@localhost ~]# echo $SHELL >> test/motd.soft 
[root@localhost ~]# ls > test/file1
[root@localhost ~]# ls -R test/* >> test/file

3、echo命令练习

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

[root@localhost ~]#  echo "$(date -R)" >> test/passwd
 [root@localhost ~]#  echo "$(date -R)" > test/group
[root@localhost ~]#  echo "$(date -R)" > test/bashrc 
[root@localhost ~]#  echo "$(date -R)" > test/profile 
[root@localhost ~]#  echo "$(date -R)" > test/sshd_config 
[root@localhost ~]# uname -n >> test/passwd
[root@localhost ~]# uname -n >> test/group 
[root@localhost ~]# uname -n >> test/bashrc 
[root@localhost ~]# uname -n >> test/profile 
[root@localhost ~]# uname -n >> 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文件中前两行内容复制至文档倒数第二行

[root@localhost ~]# cat /etc/passwd > test/passwd 
[root@localhost ~]# vim test/passwd 
		:%s/root/admin/g
		
[root@localhost ~]# cat /etc/group | grep root > test/group

[root@localhost ~]# grep -v "#" /root/.bashrc > test/bashrc 

[root@localhost ~]# cat /etc/ssh/ssh_config > test/sshd_config 
[root@localhost ~]# vim test/sshd_config 
	命令行模式:17gg
	输入模式:Port 22
	底线命令模式: :40,50s/yes/no/g 
								:w /test/sshd.conf

5、文件内容查看:

(1)查看/etc/passwd文件的第6行
(2)查看/etc/selinux/config 以 SELINUX开头的行
(3)查找/etc/ssh/sshd_config 以no结尾的行
(4)过滤/etc/ssh/sshd_config 包含数字的行

[root@localhost ~]# head -n 6 /etc/passwd | tail -1
[root@localhost ~]# cat /etc/selinux/config | grep ^SELINUX
[root@localhost ~]# cat /etc/ssh/ssh_config | grep no$
[root@localhost ~]# cat /etc/ssh/ssh_config | grep [0-9]

6、文本处理命令:

(1)查看/etc/passwd文件以 : 为分隔符的第一列内容,并按字母逆序排序
(2)使用cut命令将当前主机的ip地址切割显示

[root@localhost ~]# cut -d: -f1 /etc/passwd | sort -r

7、复制、移动

(1)在/test目录下创建一个子目录dir,将/etc/passwd复制到该目录
(2)将/etc/ssh/sshd_config文件复制到/test目录
(3)将/etc/yum.repos.d/目录复制到/test目录
(4)将/etc/hosts文件复制到/test目录
(5)将/etc/hostname文件复制到/test目录
(6)将/test/sshd_config文件移动到/test/dir目录下并改名为sshd.conf

cp 
cp -r
m

8、文件查找

(1)在/etc/目录下寻找以host开头的文件
(2)在/test/下面查找目录文件
(3)在/test目录及子目录中,查找超过2KB的文件

[root@localhost ~]# find /etc -name "host*" 
[root@localhost ~]# find /etc/ -type d
[root@localhost ~]# find /etc/ -size +2k

9、打包压缩

(1)将/test目录下的文件全部打包并用gzip压缩成/test/newfile.tar.gz
(2)将newfile.tar.gz下载至windows客户端主机
(3)在/test目录内,备份/etc下的所有文件并保留其权限

[root@localhost ~]# tar -zcvf test/newfile.tar.gz test/
2:使用图形化工具下载
3:不会

10、创建mygroup组,group组,GID为600的temp组及组id为40000的adminuser组

[root@localhost ~]# groupadd mygroup
[root@localhost ~]# groupadd group
[root@localhost ~]# groupadd -g 600 temp
[root@localhost ~]# groupadd -g 4000 adminuser

11、创建myuser用户属于mygroup组群,接着以myuser身份登录,创建ex和hv两个文件于/home/myuser目录,并使hv文件的同组用户是root。请依次写出相应执行的命令

[root@localhost ~]# useradd myuser -g mygroup
[root@localhost ~]# su myuser
[root@localhost ~]# chown -R root /home/myuser/hv/

12、添加一新用户helen并设置其用户主目录/helen,密码为空,并将temp组群作为用户helen的附加组群。请依次写出相应执行的命令

[root@localhost ~]# useradd -d /helen helen -G temp

13、创建用户user,密码为“a1b2c3”,并将其加入group组群

[root@localhost ~]# useradd user -p a1b2c3 -g group

14、新建一个名为sarah的用户,不属于adminuser组,并将其shell设置为不可登陆shell

[root@localhost ~]# useradd serah -s /bin/

15、创建alex用户,使alex用户满足以下要求:用户id为3456,描述名为alian,密码为glegunge,附属组为group

[root@localhost ~]# useradd alex -u 3456 -c alian -p glegunle -G group

16、创建 admin用户,无密码,描述为teshu,设置基本组为temp

[root@localhost ~]# useradd admin -c shehu -g temp

17、设置权限,要求如下:

(1)创建g1组,要求创建一个属于redhat用户g1组的文件redhat.txt
(2)新建/sc目录,所属组为group组,root用户和group组用户可在该目录下创建文件,其他人无任何权限
(3)新建/cw目录为财务部存储目录,只能对财务部人员可以写入,并且财务部人员所建立的文件都自动属于mygroup组中
(4)设置 helen用户对于/sc和/cw目录可以读,写,执行

[root@localhost ~]# useradd reahat
[root@localhost ~]# groupadd g1
[root@localhost ~]# touch test/redhat.txt
[root@localhost ~]# chgrp g1 test/redhat.txt 
[root@localhost ~]# chown reahat test/redhat.txt 

[root@localhost ~]# mkdir /sc
[root@localhost ~]# chown root:group /sc
oot@localhost /]# chmod -R 770 /sc

[root@localhost /]# useradd caiwu
[root@localhost /]# mkdir /cw
[root@localhost /]# chgrp caiwu /cw/
[root@localhost /]# chmod 770 /cw/

[root@localhost /]# setfacl -m u:helen:rwx /sc
[root@localhost /]# setfacl -m u:helen:rwx /cw

18、基本存储配置

1) 添加一块10G大小的磁盘,将该磁盘分为两个主分区,大小为1G、2G。将剩余的空间全部划分为扩展分区。划分一个逻辑分区,大小为3G。(主分区文件系统类型为ext4,逻辑分区文件系统类型为xfs)
2) 将三个分区分别挂载到/dir1、/dir2、/dir3。
3) 在第一个主分区中创建一个文件为file1,内容为this is partition1。在第二个分区中创建一个文件为file2,内容为this is partition2。在第三个分区中创建一个文件为file3,内容为this is partition3。

fdisk /dev/nvme0n2

[root@zhujd ~]# mount /dev/mvme0n2p1 /dir1
[root@zhujd ~]# mount /dev/mvme0n2p2 /dir2
[root@zhujd ~]# mount /dev/mvme0n2p5 /dir3