csa第一次作业

课堂练习

  1. 将/etc/passwd文件的第10-20行内容写入/root/passwd中(head,tail)

[root@localhost ~]# head -20 /etc/passwd | tail -10 > /root/passwd

[root@localhost ~]# cat /root/passwd

games:x:12:100:games:/usr/games:/sbin/nologin

ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin

nobody:x:65534:65534:Kernel Overflow User:/:/sbin/nologin

systemd-coredump:x:999:997:systemd Core Dumper:/:/sbin/nologin

dbus:x:81:81:System message bus:/:/sbin/nologin

polkitd:x:998:996:User for polkitd:/:/sbin/nologin

avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin

tss:x:59:59:Account used for TPM access:/dev/null:/sbin/nologin

colord:x:997:993:User for colord:/var/lib/colord:/sbin/nologin

clevis:x:996:992:Clevis Decryption Framework unprivileged user:/var/cache/clevis:/usr/sbin/nologin

  1. 将/etc/passwd文件中的用户名信息切割出来写入文件/root/user中(cut,>)

[root@localhost ~]# cut -d ":" -f 1 /etc/passwd > /root/user

[root@localhost ~]# cat /root/user

  1. 将/etc/group文件中的用户组信息切割出来写入文件/root/group中(cut,>)

[root@localhost ~]# cut -d ":" -f 1 /etc/group  > /root/group

  1. 在/root创建目录user-group目录,将/root/user文件和/root/group文件复制到该目录(mkdir,cp)

[root@localhost ~]# mkdir /root/user-group

[root@localhost ~]# ls -ld /root/user-group/

drwxr-xr-x. 2 root root 6  5月 22 21:27 /root/user-group/

[root@localhost ~]# cp /root/user /root/user-group/

[root@localhost ~]# cp /root/group /root/user-group/

[root@localhost ~]# cd /root/user-group/

[root@localhost user-group]# ls

group  user

  1. 打包压缩/root/passwd和/root/user-group文件为/root/up.tar.bz2(tar)

[root@localhost ~]# tar -cjvf  up.tar.bz2 passwd user-group/

passwd

user-group/

user-group/user

user-group/group

[root@localhost ~]# ls -ld up.tar.bz2

-rw-r--r--. 1 root root 898  5月 22 21:32 up.tar.bz2

  1. 查询/root/user中有没有root的行信息(grep)

[root@rhcsa ~]# grep root /root/user

root

  1. 添加用户wukong,wuneng,wujing(useradd)

[root@localhost ~]# useradd wukong

[root@localhost ~]# useradd wuneng

[root@localhost ~]# useradd wujing

[root@localhost ~]# tail -5 /etc/passwd

systemd-oom:x:978:978:systemd Userspace OOM Killer:/:/usr/sbin/nologin

redhat:x:1000:1000:redhat:/home/redhat:/bin/bash

wukong:x:1001:1001::/home/wukong:/bin/bash

wuneng:x:1002:1002::/home/wuneng:/bin/bash

wujing:x:1003:1003::/home/wujing:/bin/bash

  1. 添加组xiyouji(groupadd)

[root@localhost ~]# groupadd xiyouji

[root@localhost ~]# tail -3 /etc/group

wuneng:x:1002:

wujing:x:1003:

xiyouji:x:1004:

  1. 将用户wukong,wuneng,wujing添加到xiyouji组(usermod)

[root@localhost ~]# usermod -G xiyouji wukong

[root@localhost ~]# usermod -G xiyouji wuneng

[root@localhost ~]# usermod -G xiyouji wujing

[root@localhost ~]# tail -3 /etc/group

wuneng:x:1002:

wujing:x:1003:

xiyouji:x:1004:wukong,wuneng,wujing

10、添加用户tangxuanzang并设置该用户的基本组为xiyouji(useradd)

[root@localhost ~]# useradd -g xiyouji tangxuanzang

[root@localhost ~]# tail -3 /etc/group

wuneng:x:1002:

wujing:x:1003:

xiyouji:x:1004:wukong,wuneng,wujing

[root@localhost ~]# tail -2 /etc/passwd

wujing:x:1003:1003::/home/wujing:/bin/bash

tangxuanzang:x:1004:1004::/home/tangxuanzang:/bin/bash

# 课后作业

  1. 修改当前主机名为rhcsa

[root@localhost ~]# hostnamectl set-hostname rhcsa

  1. 在/home/和/root目录下面创建file1文件和dir1目录

[root@rhcsa ~]# mkdir dir1

[root@rhcsa ~]# touch file1

[root@rhcsa ~]# ls -l /root

[root@rhcsa ~]# cd /home

[root@rhcsa home]# mkdir dir1

[root@rhcsa home]# touch file1

[root@rhcsa home]# ls -l

  1. 在/home/file1文件里面写入内容hello,welcome to home

[root@rhcsa home]# vim file1

[root@rhcsa home]# cat file1

hello,welcome to home

  1. 在/root/file1文件里面写入当前的时间并写入内容this is administrator

[root@rhcsa ~]# date > /root/file1

[root@rhcsa ~]# echo this is administrator >> /root/file1

[root@rhcsa ~]# cat /root/file1

2023年 05月 23日 星期二 14:24:07 CST

this is administrator

5、在/root/dir1目录下面新建文件file2,内容和/root/file1文件内容一样

[root@rhcsa ~]# cd /root/dir1

[root@rhcsa dir1]# touch file2

[root@rhcsa dir1]# cp /root/file1 file2

cp:是否覆盖'file2'? yes

[root@rhcsa dir1]# more file2

2023年 05月 23日 星期二 14:24:07 CST

this is administrator

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值