Linux第二周

第二周

1、显示/etc目录以非字母开头后面跟了一个字母以及其它任意长度任意字符的文件或目录

#新建一个符合条件的文件“1a2b3c.txt”
[root@localhost ~]# cd /etc
[root@localhost etc]# touch 1a2b3c.txt
#用grep进行匹配要求文件
[root@localhost etc]# ls | grep -E '^[^a-Z][a-Z].*'
1a2b3cd.txt
#验证(如图)

2、复linux是什么操作系统制/etc目录下所有以p开头,以非数字结尾的文件或目录到/tmp/mytest1目录中。

#创建mytest1文件夹
[root@localhost tmp]# mkdir /tmp/mytest1
#目标文件或目录到/tmp/mytest1目录中
[root@localhost ~]# cd /etc
[root@localhost etc]# ls |grep -E "^[p].*[^[:digit:]]$" |xargs -i cp -r {} /tmp/mytest1
#验证
[root@localhost etc]# cd ../tmp/mytest1
[root@localhost mytest1]# ll


                                            Linux第二周

3、将/etc/issue文件系统/运维中的内容转换为大写后保系统运维的主要任务存至/tmp/is系统运维工程师sue.out文件中

#查看一下目标文件
[root@localhost ~]# cat /etc/issue
\S
Kernel \r on an \m
#文件中的内容转换为大写后保存至/tmp/issue.out文件中
[root@localhost ~]# cat /etc/issue | tr a-z A-Z >/tmp/issue.out
#验证
[root@localhost ~]# cd /tmp
[root@localhost tmp]# ls
issue.out mkdir.sh systemd-private-02b5fb8aa860494686e1ef8736879488-chronyd.service-Uo4Dqg vmware-root_858-2722632195
lua_jjLYR6 mytest1 tmp2x36xgab vmware-root_880-2697139639
[root@localhost tmp]# cat issue.out


                                            Linux第二周

4、请总结描述用户和组管系统运维主要做什么理类命令的使用方法并完成以下练习:

(1)、创建组distro,其GID为2019;

[root@localhost tmp]# groupadd -g 2019 distro
#验证:
[root@localhost tmp]# cat /etc/group


                                            Linux第二周

(2)、创建用户mandriva, 其ID号为1005;基本组为distro;

[root@localhost tmp]# useradd -g distro -u 1005 mandriva
#验证
[root@localhost tmp]# cat /etc/passwd


                                            Linux第二周

(3)、创建用户mageia,其ID号为1100,家目录为/home/linux;

[root@localhost tmp]# useradd -m -d  /home/linux -u 1100 mageia    #不支持-d -m
#验证
[root@localhost tmp]# cat /etc/passwd


                                            Linux第二周

(4)、给用户mageia添加密码,密码为mageedu,并设置用户密码7天后过期

[root@localhost tmp]# passwd mageia
更改用户 mageia 的密码 。
新的 密码:
passwd:所有的身份验证令牌已经成功更新。
[root@localhost tmp]# passwd -x +7 mageia
调整用户密码老化数据mageia。
passwd: 操作成功

(5)、删除mandriva,但保留其家目录;

#删除mandriva,但保留其家目录
[root@localhost ~]# userdel mandriva
#验证(已删除无次用户)


                                            Linux第二周

验证(可进入删除用户的家目录)
[root@localhost ~]# cd /home/mandriva
[root@localhost mandriva]#


                                            Linux第二周

(6)、创建用户slackware,其linux必学的60个命令ID号为2002,基本组为distro,附加组peguin;

[root@localhost ~]# groupadd peguin
[root@localhost ~]# useradd -u 1005 -g distro -G peguin slackware
#验证
[root@localhost ~]# cat /etc/group


                                            Linux第二周

(7)、修改slackware的默认shell为/bin/tcsh;

[root@localhost ~]# usermod -s tcsh slackware
#验证
[root@localhost ~]# cat /etc/passwd


                                            Linux第二周

(8)、为用户slackwarelinux常用命令新增附加组admins,并设置不可登陆。

[root@localhost ~]# groupadd admins;usermod -G admins -L slackware

5、创建用户user1、user2、user3。在/d系统运维的主要任务ata/下创建目录test

[root@localhost ~]# seq 1 3 | xargs -i useradd user{} ;mkdir /data/test

(1)、目录/data/test属主、属组为user1

[root@localhost data]# chown -R user1:user1 test
[root@localhost data]# ll
总用量 8
-rwxr-xr-x. 1 root root 32 116 22:52 hello.sh
-rwxr-xr-x. 1 root root 1088 116 23:47 system_info.sh
drwxr-xr-x. 2 user1 user1 6 1126 22:30 test

(2)、在目录属主系统运维包括哪些内容、属组不变的情况下,user2对文件有读写权限

[root@localhost data]# usermod -a -G user1 user2
[root@localhost data]# ll
总用量 8
-rwxr-xr-x. 1 root root 32 116 22:52 hello.sh
-rwxr-xr-x. 1 root root 1088 116 23:47 system_info.sh
drwxr-xr-x. 2 user1 user1 6 1126 22:30 test

(3)、user1在/data/test目录下创建文件a1.sh, a2.sh, a3.sh, a4.s系统/运维h,设置所有用户都不可删除1.sh,2.sh文件、除了user1及root之外系统运维工程师面试问题及答案linux必学的60个命令所有用户都不可删除a3.sh, a4.sh

[root@localhost data]# su user1
[user1@localhost data]$ ll
总用量 8
-rwxr-xr-x. 1 root root 32 116 22:52 hello.sh
-rwxr-xr-x. 1 root root 1088 116 23:47 system_info.sh
drwxr-xr-x. 2 user1 user1 6 1126 22:30 test
[user1@localhost data]$ cd test
[user1@localhost test]$ seq 1 4 | xargs -i touch a{}.sh
[user1@localhost test]$ ll
总用量 0
-rw-rw-r--. 1 user1 user1 0 1126 23:34 a1.sh
-rw-rw-r--. 1 user1 user1 0 1126 23:34 a2.sh
-rw-rw-r--. 1 user1 user1 0 1126 23:34 a3.sh
-rw-rw-r--. 1 user1 user1 0 1126 23:34 a4.sh
#设置所有用户都不可删除1.sh,2.sh文件
[user1@localhost test]$ su root
密码:
[root@localhost test]# chattr +i a{1,2}.sh
[root@localhost test]# lsattr
----i--------------- ./a2.sh
-------------------- ./a3.sh
-------------------- ./a4.sh
----i--------------- ./a1.sh
[root@localhost test]# rm -rf a1.sh
rm: 无法删除'a1.sh': 不允许的操作
[root@localhost test]# su user1
[user1@localhost test]$ rm -rf a1.sh
rm: 无法删除'a1.sh': 不允许的操作
#除了user1及root之外,所有用户都不可删除a3.sh, a4.sh
[user1@localhost test]$ chmod o+x a{3,4}.sh
[user1@localhost test]$ chmod o+t a{3,4}.sh

(4)、user3增加附加组user1,同时要求user1不系统运维工作内容能访问/data/linux常用命令test目录及其下所有文件

[root@localhost test]# usermod -a -G user1 user3
[root@localhost test]# id user3
uid=1103(user3) gid=1103(user3) 组=1103(user3),1101(user1)
[root@localhost test]# setfacl -m u:user1:- /data/test/

(5)、清理/data/test目录及其下所有文件的acl权限

[user1@localhost test]$ setfacl -R -b /data/test/
[user1@localhost test]$ getfacl /data/test/
getfacl: Removing leading '/' from absolute path names
# file: data/test/
# owner: user1
# group: user1
user::rwx
group::r-x
other::r-x
user1@localhost test]$ ll
总用量 0
-r--r--r--. 1 user1 user1 0 1127 00:16 a1.sh
-r--r--r--. 1 user1 user1 0 1126 23:34 a2.sh
-rw-rw-r-t. 1 user1 user1 0 1126 23:34 a3.sh
-rw-rw-r-t. 1 user1 user1 0 1126 23:34 a4.sh