RHCSA第五次作业

RHCSA第五次作业,第1张

课后作业: 1.使用tar命令对文件进行打包压缩与解压缩: (1)使用gzip方式对文件进行压缩,并指定压缩名为 tar_gzip.tar.gz
[root@localhost ~]# touch tar.test{1..2}
[root@localhost ~]# tar -czvf tar_gzip.tar tar.test{1..2}
tar.test1
tar.test2
[root@localhost ~]# ls
anaconda-ks.cfg                        file2                 result.txt        tar.test2
baidu.html                             file3                 right.txt         test
CentOS-Base.repo                       index.html            sorted_args.txt   test2
Centos-vault-8.5.2111.repo             index.html.1          sorted_merge.txt  text
cont-1752223-10057823-171629-hd.mp4    initial-setup-ks.cfg  sorted_num.txt
cont-1755372-15845298_adpkg-ad_hd.mp4  link_test             tar_gzip.tar
file1                                  parent                tar.test1
(2)使用bzip2方式对文件夹进行压缩,并指定压缩名为 tar_bzip2.tar.bz2
[root@localhost ~]# touch tar_btest{1..2}
[root@localhost ~]# tar -cjvf tar_bzip2.tar.bz2 tar_btest{1..2}
tar_btest1
tar_btest2
[root@localhost ~]# ls
anaconda-ks.cfg                        file1                 link_test         sorted_num.txt     tar.test2
baidu.html                             file2                 parent            tar_btest1         test
CentOS-Base.repo                       file3                 result.txt        tar_btest2         test2
Centos-vault-8.5.2111.repo             index.html            right.txt         tar_bzip2.tar.bz2  text
cont-1752223-10057823-171629-hd.mp4    index.html.1          sorted_args.txt   tar_gzip.tar
cont-1755372-15845298_adpkg-ad_hd.mp4  initial-setup-ks.cfg  sorted_merge.txt  tar.test1
(3) 使用xz方式对文件进行压缩,并指定压缩名为 tar_xz.tar.xz
[root@localhost ~]# touch tar_xtest{1..2}
[root@localhost ~]# tar -cJvf tar_xz.tar.xz tar_xtest{1..2}
tar_xtest1
tar_xtest2
[root@localhost ~]# ls
anaconda-ks.cfg                        file2                 result.txt        tar_bzip2.tar.bz2  test
baidu.html                             file3                 right.txt         tar_gzip.tar       test2
CentOS-Base.repo                       index.html            sorted_args.txt   tar.test1          text
Centos-vault-8.5.2111.repo             index.html.1          sorted_merge.txt  tar.test2
cont-1752223-10057823-171629-hd.mp4    initial-setup-ks.cfg  sorted_num.txt    tar_xtest1
cont-1755372-15845298_adpkg-ad_hd.mp4  link_test             tar_btest1        tar_xtest2
file1                                  parent                tar_btest2        tar_xz.tar.xz
(4) 新建文件file1.txt,file2.txt,file3.txt
[root@localhost ~]# touch file{1..3}.txt
[root@localhost ~]# ls
anaconda-ks.cfg                        file1.txt     initial-setup-ks.cfg  sorted_num.txt     tar_xtest1
baidu.html                             file2         link_test             tar_btest1         tar_xtest2
CentOS-Base.repo                       file2.txt     parent                tar_btest2         tar_xz.tar.xz
Centos-vault-8.5.2111.repo             file3         result.txt            tar_bzip2.tar.bz2  test
cont-1752223-10057823-171629-hd.mp4    file3.txt     right.txt             tar_gzip.tar       test2
cont-1755372-15845298_adpkg-ad_hd.mp4  index.html    sorted_args.txt       tar.test1          text
file1                                  index.html.1  sorted_merge.txt      tar.test2
(5)对文件file1.txt和file2.txt,进行压缩(使用gzip方式),排除file3.txt(即不对file3进行压缩) 并指定压缩名为tar_file.tar.gz
[root@localhost ~]# tar --exclude=file3.txt -czvf tar_file.tar.gz file{1..3}.txt
file1.txt
file2.txt
[root@localhost ~]# ls
anaconda-ks.cfg                        file1.txt     initial-setup-ks.cfg  sorted_num.txt     tar.test2
baidu.html                             file2         link_test             tar_btest1         tar_xtest1
CentOS-Base.repo                       file2.txt     parent                tar_btest2         tar_xtest2
Centos-vault-8.5.2111.repo             file3         result.txt            tar_bzip2.tar.bz2  tar_xz.tar.xz
cont-1752223-10057823-171629-hd.mp4    file3.txt     right.txt             tar_file.tar.gz    test
cont-1755372-15845298_adpkg-ad_hd.mp4  index.html    sorted_args.txt       tar_gzip.tar       test2
file1                  
(6)新建文件file4.txt,将file4.txt添加到tar_file.tar.gz中
[root@localhost ~]# tar --exclude=file3.txt -cvf tar_file.tar.gz file{1..3}.txt
file1.txt
file2.txt
[root@localhost ~]# tar -rvf tar_file.tar.gz file4.txt
tar: file4.txt: Cannot stat: No such file or directory
tar: Exiting with failure status due to previous errors
[root@localhost ~]# tar -tvf tar_file.tar.gz
-rw-r--r-- root/root         0 2022-05-05 15:42 file1.txt
-rw-r--r-- root/root         0 2022-05-05 15:42 file2.txt
(7)查看压缩包tar_file.tar.gz有哪些文件及目录(不解压,只查看)
[root@localhost ~]# tar -tvf tar_file.tar.gz
-rw-r--r-- root/root         0 2022-05-05 15:42 file1.txt
-rw-r--r-- root/root         0 2022-05-05 15:42 file2.txt
(8)解压tar_gzip.tar.gz到指定目录tar_test(没有这个目录就创建)
[root@localhost ~]# mkdir tar_test
[root@localhost ~]# tar -xzvf tar_gzip.tar -C tar_test
tar.test1
tar.test2
(9)解压tar_xz.tar.xz
[root@localhost ~]# tar -xvJf tar_xz.tar.xz
tar_xtest1
tar_xtest2
2.在Linux上的/root目录创建一个Linux.txt,在windows上创建windows.txt (1)通过sftp的 get和put命令,将windows上的windows.txt推送到linux上
C:\Users\不长记性>sftp root@192.168.142.128
root@192.168.142.128's password:
Connected to 192.168.142.128.
sftp> put windows.txt
[root@localhost ~]# ls
anaconda-ks.cfg                        file2                 parent            tar_bzip2.tar.bz2  tar_xz.tar.xz
baidu.html                             file2.txt             result.txt        tar_file.tar.gz    test
CentOS-Base.repo                       file3                 right.txt         tar_gzip.tar       test2
Centos-vault-8.5.2111.repo             file3.txt             sorted_args.txt   tar_test           text
cont-1752223-10057823-171629-hd.mp4    index.html            sorted_merge.txt  tar.test1          windows,txt
cont-1755372-15845298_adpkg-ad_hd.mp4  index.html.1          sorted_num.txt    tar.test2          windows.txt
file1                                  initial-setup-ks.cfg  tar_btest1        tar_xtest1
file1.txt                              link_test             tar_btest2        tar_xtest2
(2)通过sftp的 get和put命令,将linux上的linux.txt推送到windows上
[root@localhost ~]# touch linux.txt
[root@localhost ~]# ls
anaconda-ks.cfg                        file2                 linux.txt         tar_btest2         tar_xtest2
baidu.html                             file2.txt             parent            tar_bzip2.tar.bz2  tar_xz.tar.xz
CentOS-Base.repo                       file3                 result.txt        tar_file.tar.gz    test
Centos-vault-8.5.2111.repo             file3.txt             right.txt         tar_gzip.tar       test2
cont-1752223-10057823-171629-hd.mp4    index.html            sorted_args.txt   tar_test           text
cont-1755372-15845298_adpkg-ad_hd.mp4  index.html.1          sorted_merge.txt  tar.test1          windows,txt
file1                                  initial-setup-ks.cfg  sorted_num.txt    tar.test2          windows.txt
file1.txt                              link_test             tar_btest1        tar_xtest1
sftp> get linux.txt
Fetching /root/linux.txt to linux.txt
(3) 使用rz上传文件windows.txt到linux上
(4)使用sz下载文件linux.txt到windows上

3.创建普通变量local_data=1并访问
[root@localhost ~]# local_data=1
[root@localhost ~]# echo $local_data
1
(1)创建环境变量ROOT_DATA=root, 只有root用户可以访问到
[root@localhost ~]# vim .bash_profile 
[root@localhost ~]# source .bash_profile
[root@localhost ~]# echo $ROOT_DATA
 (2)创建环境变量USER_DATA=user, 只有普通用户可以访问到
[root@localhost ~]# vim .bash_profile
[root@localhost ~]# source .bash_profile
[root@localhost ~]# echo $USER_DATA
 (3)创建环境变量DATA=all, root用户和普通用户都可以访问到
[root@localhost ~]# vim /etc/profile
[root@localhost ~]# source /etc/profile
[root@localhost ~]# echo $DATA
[root@localhost ~]# su - rhcsa
[rhcsa@localhost ~]$ echo $DATA
4.创建3个文件test1.txt, test2.txt, test3.txt
[rhcsa@localhost ~]$ touch test{1..3}.txt
 (1)使用find查找test1.txt,test2.txt, test3.txt
[rhcsa@localhost ~]$ find test{1..3}.txt
test1.txt
test2.txt
test3.txt
(2)使用别名: 将上边命令命名为myfind
[rhcsa@localhost ~]$ alias myfind="find . -name 'test*.txt'"
[rhcsa@localhost ~]$ myfind
./test/test2.txt
./test/test1.txt
./test1.txt
./test2.txt
./test3.txt
 (3)取消别名
[rhcsa@localhost ~]$ unalias myfind
[rhcsa@localhost ~]$ myfind
bash: myfind: command not found...
5.查看最近使用的10条历史命令
[rhcsa@localhost ~]$ history 10
   50  ls
   51  pwd
   52  echo $DATA
   53  touch test{1..3}.txt
   54  find test{1..3}.txt
   55  alias myfind="find . -name 'test*.txt'"
   56  myfind
   57  unalias myfind
   58  myfind
   59  history 10
6.在一行上执行两个命令,打印123和从root切换到普通用户
[rhcsa@localhost ~]$ echo 123;su - rhcsa
123
Password: 
7.通配符使用 (1) 创建3个文件 file1, file2, file3
[rhcsa@localhost ~]$ touch file{1..3}
[rhcsa@localhost ~]$ ls
Desktop    Downloads  file2  input.txt  Pictures  redirect.txt  test              test1.txt  test2.txt  text
Documents  file1      file3  Music      Public    Templates     test111_symb.txt  test2      test3.txt  Videos
 (2)* 去匹配3个文件
[rhcsa@localhost ~]$ ls -l file*
-rw-rw-r--. 1 rhcsa rhcsa 0 May  6 06:43 file1
-rw-rw-r--. 1 rhcsa rhcsa 0 May  6 06:43 file2
-rw-rw-r--. 1 rhcsa rhcsa 0 May  6 06:43 file3
(3)[]匹配file1和file3 
[rhcsa@localhost ~]$ ls -l file[1,3]
-rw-rw-r--. 1 rhcsa rhcsa 0 May  6 06:43 file1
-rw-rw-r--. 1 rhcsa rhcsa 0 May  6 06:43 file3
 (4)? 匹配3个文件
[rhcsa@localhost ~]$ ls -l file?
-rw-rw-r--. 1 rhcsa rhcsa 0 May  6 06:43 file1
-rw-rw-r--. 1 rhcsa rhcsa 0 May  6 06:43 file2
-rw-rw-r--. 1 rhcsa rhcsa 0 May  6 06:43 file3
(5)[^]匹配file2
[rhcsa@localhost ~]$ ls -l file[^1,3]
-rw-rw-r--. 1 rhcsa rhcsa 0 May  6 06:43 file2
(6){}匹配file1和file3
[rhcsa@localhost ~]$ ls -l file{1,3}
-rw-rw-r--. 1 rhcsa rhcsa 0 May  6 06:43 file1
-rw-rw-r--. 1 rhcsa rhcsa 0 May  6 06:43 file3
(7)[!]匹配file2
[rhcsa@localhost ~]$ ls -l file[!1,3]
-rw-rw-r--. 1 rhcsa rhcsa 0 May  6 06:43 file2
8.引号的使用举例: 无引号,单引号,双引号,反引号,$()
[rhcsa@localhost ~]$ echo kylin
kylin
[rhcsa@localhost ~]$ echo 'kylin'
kylin
[rhcsa@localhost ~]$ echo "kylin"
kylin
[rhcsa@localhost ~]$ echo `pwd`
/home/rhcsa
[rhcsa@localhost ~]$ echo $(pwd)
/home/rhcsa
9.linux中用户的类型

(1)linux中用户组的类型

基本组又叫私有组,建立账户时,若没有指定账户所属的组,系统会建立一个和用户名相同的组。基本组只能容纳一个用户,当把其他用户加入到该组中,则基本组就变成了附加组。
附加组又叫公有组,可以容纳多个用户,组中的用户都具有组所拥有的权力。
系统组一般加入一些系统用户。

(2)linux中存储用户信息的文件是哪个?且其中的字段是什么意思

① 存储用户信息的文件是 /etc/passwd
② 各字段含义

字段含义解释
第一个字段账号名称用户登录Linux系统时使用的用户名称
第二个字段密码密码占位符" x " 或" * " 。若为 “x” ,说明密码经过了 shadow 的保护
第三个字段UID用户ID
第四个字段GID用户所在基本组的标识,是一个数值,用它来区分不同的组
第五个字段个人资料可以记录用户的完整姓名、地址、办公室电话、家庭电话等个人信息
第六个字段主目录类似Windows 的个人目录,通常是/home/username
第七个字段Shell定义用户登录后激活的Shell,默认是Bash Shell

(3)linux中存储组信息的文件是哪个?且其中的字段是什么意思?

① 存储组信息的文件是 /etc/group
②各字段含义

字段含义
第一个字段组的名字
第二个字段组的加密口令
第三个字段是系统区分不同组的ID,在/etc/passwd域中的GID 字段是用这个数来指定用户的基本组
第四个字段是用 “,” 分开的用户名,列出的是附加组的成员
10.创建下列用户、组和组成员资格:

(1)创建名为 sysmgrs 的组

[rhcsa@localhost ~]$ groupadd sysmgts

 (2)创建用户 natasha 同时指定sysmgrs作为natasha的附加组

[rhcsa@localhost ~]$ useradd natasha
[rhcsa@localhost ~]$ gpasswd -a natasha sysmgts

(3)创建用户 harry 同时指定 sysmgrs作为harry的附加组

[rhcsa@localhost ~]$ useradd harry
[rhcsa@localhost ~]$ gpasswd -a harry sysmgts

(4)创建用户 sarah 指定shell类型为/sbin/false(无权访问系统上的交互式 shell)
  且不是 sysmgrs 的成员

[rhcsa@localhost ~]$ useradd -s /sbin/false sarah
[rhcsa@localhost ~]$ tail /etc/group

 (5)设置natasha 、 harry 和 sarah 的密码都是 123

[rhcsa@localhost ~]$ passwd natasha
[rhcsa@localhost ~]$ passwd harry
[rhcsa@localhost ~]$ passwd sarah

 (6)创建用户lockuser, 并指定家目录为/home/lock, 然后锁定该用户

[rhcsa@localhost ~]$ useradd -d /home/lock lockuser
[rhcsa@localhost ~]$ passwd -l lockuser
[rhcsa@localhost ~]$ passwd -S lockuser

(7)创建用户limituser, gid为1555,userid为1666, 让其密码在10天后过期

[rhcsa@localhost ~]$ useradd -p 1555 -f 10 limituser
[rhcsa@localhost ~]$ useradd -p 1555 -f 10 gid
[rhcsa@localhost ~]$ useradd -p 1666 -f 10 userid

 (8)解锁lockuser, 并设定下次登录时必须修改密码

[rhcsa@localhost ~]$ passwd -u lockuser
[rhcsa@localhost ~]$ passwd -u -f lockuser

 (9)让natasha具备修改 harry密码的权限(sudo)
   visudo
   Host_Alias RHCSA=lwz
   User_Alias USER11=natasha
   Cmnd_Alias CHPASS=/usr/bin/passwd harry
   USER RCHSA=(root)  CHPASS

[rhcsa@localhost ~]$ su - natasha
[rhcsa@localhost ~]$ sudo passwd harry

 (10)创建用户testuser并设置密码,修改用户名为normaluser   

[rhcsa@localhost ~]$ useradd -p "xin" testuser
[rhcsa@localhost ~]$ usermod -l normaluser testuser
11.删除lockuser
[rhcsa@localhost ~]$ userdel -r limituser

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/langs/872461.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-13
下一篇2022-05-13

发表评论

登录后才能评论

评论列表(0条)

    保存