RHCSA第二次作业

1、文件查看: 查看/etc/passwd文件的第5行

[root@server ~]# head -5 /etc/passwd |tail -1
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin

2、文件查找

(1)在当前目录及子目录中,查找大写字母开头的txt文件
(2)在/etc及其子目录中,查找host开头的文件
(3)在$HOME目录及其子目录中,查找所有文本文件
(4)忽略文件名大小写查找a.txt

[root@server ~]# touch B.txt
[root@server ~]# find . -name "[A-Z]*.txt"
./B.txt
[root@server ~]# find /etc/ -name "host*"
/etc/host.conf
/etc/hosts
/etc/avahi/hosts
/etc/nvme/hostnqn
/etc/nvme/hostid
/etc/hostname
[root@server ~]# find $HOME -name "*"
[root@server ~]# touch A.txt
[root@server ~]# touch a.txt
[root@server ~]# ls
公共  视频  文档  音乐  anaconda-ks.cfg  A.txt
模板  图片  下载  桌面  a.txt            B.txt
[root@server ~]# find . -iname "a.txt"
./A.txt
./a.txt

3、查找文件 /etc/passwd中包含字符串 ro 的所有行。将所有这些行的副本按原始顺序放在文件/root/files1中

[root@server ~]# grep "ro" /etc/passwd
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
rtkit:x:172:172:RealtimeKit:/proc:/sbin/nologin
setroubleshoot:x:992:988:SELinux troubleshoot server:/var/lib/setroubleshoot:/sbin/nologin
chrony:x:986:981::/var/lib/chrony:/sbin/nologin
[root@server ~]# grep "ro" /etc/passwd > /root/files1
[root@server ~]# cat /root/files1
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
rtkit:x:172:172:RealtimeKit:/proc:/sbin/nologin
setroubleshoot:x:992:988:SELinux troubleshoot server:/var/lib/setroubleshoot:/sbin/nologin
chrony:x:986:981::/var/lib/chrony:/sbin/nologin

4、将整个 /etc 目录下的文件全部打包并用 gzip 压缩成/back/etcback.tar.gz

[root@server ~]# mkdir back
[root@server ~]# ls
公共  视频  文档  音乐  anaconda-ks.cfg  A.txt  B.txt
模板  图片  下载  桌面  a.txt            back   files1
[root@server ~]# tar cvf /back/etcback.tar.gz /etc/
tar: Removing leading ‘/’ from member names
/etc/
/etc/mtab
/etc/fstab
/etc/crypttab
/etc/Lum/
/etc/lum/devices/
/etc/lum/devices/system.devices
/etc/lvm/archive/
/etc/lvm/archive/rhel_00000-1378882030.vg
/etc/lvm/backup/
/etc/lvm/backup/rhel
/etc/lum/cache/
/etc/lum/lvm.conf
/etc/lum/lumlocal.conf
/etc/lum/profile/
/etc/lvm/profile/cache-mq.profile
/etc/lvm/profile/cache-smq.profile
/etc/lvm/profile/command profile_ template.profile
/etc/lvm/profile/lvmdbusd.profile
/etc/lvm/profile/metadata profile template.profile
/etc/lvm/profile/thin-generic.profile
/etc/lvm/profile/thin-performance.profile
/etc/lvm/profile/vdo-small.profile
/etc/resolv.conf
/etc/dnf/
/etc/dnf/modules.d/
/etc/dnf/aliases.d/
/etc/dnf/dnf.conf
/etc/dnf/modules.defaults.d/
/etc/dnf/plugins/
/etc/dnf/pluqins/copr.conf
/etc/dnf/plugins/copr.d/
/etc/dnf/plugins/debuginfo-install.conf
/etc/dnf/plugins/kpatch.conf
/etc/dnf/plugins/product-id.conf
/etc/dnf/plugins/subscription-manager.conf
[root@server ~]# ls /back
etcback.tar.gz

5、使当前用户永久生效的命令别名: 写一个命令命为hello,实现的功能为每输入一次hello命令,就有"hello,everyone"写入文件/file2中。

[root@server ~]# alias hello='echo hello everyone >> /file2.txt'
[root@server ~]# hello
[root@server ~]# cat /file2.txt
hello everyone

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

[root@server home]# groupadd mygroup
[root@server home]# useradd -g mygroup myuser
[root@server home]# ll
总用量 8
drwxr-xr-x. 2 root root    6  5月  4 15:38 公共
drwxr-xr-x. 2 root root    6  5月  4 15:38 模板
drwxr-xr-x. 2 root root    6  5月  4 15:38 视频
drwxr-xr-x. 2 root root    6  5月  4 15:38 图片
drwxr-xr-x. 2 root root    6  5月  4 15:38 文档
drwxr-xr-x. 2 root root    6  5月  4 15:38 下载
drwxr-xr-x. 2 root root    6  5月  4 15:38 音乐
drwxr-xr-x. 2 root root    6  5月  4 15:38 桌面
-rw-------. 1 root root 1352  4月 26 21:58 anaconda-ks.cfg
-rw-r--r--. 1 root root    0  5月 12 21:24 a.txt
-rw-r--r--. 1 root root    0  5月 12 21:24 A.txt
drwxr-xr-x. 3 root root   24  5月 12 21:35 back
-rw-r--r--. 1 root root    0  5月 12 21:13 B.txt
-rw-r--r--. 1 root root  264  5月 12 21:27 files1
[root@server home]# ls
luyilin  myuser  redhat
[root@server home]# ll
总用量 4
drwx------. 14 luyilin luyilin 4096  4月 26 22:00 luyilin
drwx------.  3 myuser  mygroup   78  5月 12 21:48 myuser
drwx------.  3 redhat  redhat    78  5月 12 21:35 redhat
[root@server home]# su - myuser
[myuser@server ~]$ touch hv ex
[myuser@server ~]$ ll
总用量 0
-rw-r--r--. 1 myuser mygroup 0  5月 12 21:50 ex
-rw-r--r--. 1 myuser mygroup 0  5月 12 21:50 hv
[myuser@server ~]$ chown :root hv
chown: 正在更改'hv' 的所属组: 不允许的操作
[myuser@server ~]$ su - root
密码: 
[root@server ~]# vim /etc/sudoers
[root@server ~]# su - myuser
[myuser@server ~]$ ll
总用量 0
-rw-r--r--. 1 myuser mygroup 0  5月 12 21:50 ex
-rw-r--r--. 1 myuser mygroup 0  5月 12 21:50 hv


7、创建g1组,要求创建一个属于redhat用户g1组的文件redhat.txt

[root@server back]# groupadd g1
[root@server back]# mkdir redhat.txt
[root@server back]# useradd redhat
[root@server back]# chown redhat:g1 redhat.txt/
[root@server back]# ll -d redhat.txt/
drwxr-xr-x. 2 redhat g1 6  5月 12 21:35 redhat.txt/

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值