一、显示/etc目录下,以非字母开头,后面跟了一个字母以及其他任意长度任意字符的文件或目录
[root@centos7 ~]#ls -dl /etc/[^[:alpha:]]*
二、复制/etc目录下所有以p开头,以非数字结尾的文件或目录到/tmp/mytest1目录中
[root@centos7 ~]# cp -af /etc/p*[^[:digit:]] /tmp/mytest1
三、将/etc/issue文件中的内容转换为大写后保存至/tmp/issue.out文件中
[root@centos7 ~]# tr ‘a-z’ ‘A-Z’< /etc/issue > /tmp/issue.out
[root@centos7 ~]# cat /tmp/issue.out
\S
KERNEL \R ON AN \M
四、请总结描述用户和组管理类命令的使用方法并完成以下练习
(1)创建组distro,其GID为2019
[root@centos7 ~]# groupadd -g 2019 distro
[root@centos7 ~]# cat /etc/group | tail -1
distro:x:2019:
(2)创建用户mandriva, 其ID号为1005;基本组为distro
[root@centos7 ~]# useradd -u 1005 -g distro mandriva
[root@centos7 ~]# id mandriva
uid=1005(mandriva) gid=2019(distro) groups=2019(distro)
(3)建用户mageia,其ID号为1100,家目录为/home/linux
[root@centos7 ~]# useradd -u 1100 -d /home/linux mageia
[root@centos7 ~]# id mageia
uid=1100(mageia) gid=1100(mageia) groups=1100(mageia)
(4)、给用户mageia添加密码,密码为mageedu,并设置用户密码7天后过期;
[root@centos7 ~]# echo "mageedu" | passwd --stdin mageia
Changing password for user mageia.
passwd: all authentication tokens updated successfully.
[root@centos7 ~]# passwd -x 7 mageia
Adjusting aging data for user mageia.
passwd: Success
[root@centos7 ~]# getent shadow mageia
mageia:$6$bNO3uOqM$D8pxt9z0gkO9PsuHUlRPP8DAYmBkJNx3D1SOGO78veNUORwA1AjEw6E.8wsyDv7QUQUgdtZk.d9/b3WjCYEsl/:18686:0:7:7:::
(5)、删除mandriva,但保留其家目录;
[root@centos7 ~]# userdel mandriva
[root@centos7 ~]# ll /home/
total 0
drwx------. 3 chen chen 111 Feb 28 16:26 chen
drwx------. 2 mageia mageia 62 Feb 28 18:39 linux
drwx------. 2 1005 distro 62 Feb 28 18:37 mandriva
(6) 创建用户slackware,其ID号为2002,基本住为distro,附加组为peguin
[root@centos7 ~]# groupadd peguin
[root@centos7 ~]# useradd -u 2002 -g distro -G peguin slackware
[root@centos7 ~]# id slackware
uid=2002(slackware) gid=2019(distro) groups=2019(distro),2020(peguin)
(7) 修改slackware的默认shell为/bin/tcsh
[root@centos7 ~]# usermod -s /bin/tcsh slackware
[root@centos7 ~]# getent passwd slackware
slackware:x:2002:2019::/home/slackware:/bin/tcsh
(8 )为用户slackware新增附加组admins,并设置不可登陆。
[root@centos7 ~]# groupadd admins
[root@centos7 ~]# usermod -s /bin/false -aG admins slackware
[root@centos7 ~]# id slackware
uid=2002(slackware) gid=2019(distro) groups=2019(distro),2020(peguin),2021(admins)
[root@centos7 ~]# getent passwd slackware
slackware:x:2002:2019::/home/slackware:/bin/false
五、创建用户user1、user2、user3。在/data/下创建目录test
[root@centos7 ~]# echo user{1..3} | xargs -n1 useradd
[root@centos7 ~]# id user1
uid=2003(user1) gid=2003(user1) groups=2003(user1)
[root@centos7 ~]# id user2
uid=2004(user2) gid=2004(user2) groups=2004(user2)
[root@centos7 ~]# id user3
uid=2005(user3) gid=2005(user3) groups=2005(user3)
[root@centos7 ~]# mkdir -p /data/test
[root@centos7 ~]# ll /data
total 0
drwxr-xr-x. 2 root root 6 Feb 28 20:59 test
(1)、目录/data/test属主、属组为user1
[root@centos7 ~]# chown -R user1:user1 /data/test
[root@centos7 ~]# ll /data
total 0
drwxr-xr-x. 2 user1 user1 6 Feb 28 20:59 test
(2)、在目录属主、属组不变的情况下,user2对文件有读写权限
[root@centos7 test]# setfacl -m u:user2:rw /data/test
[root@centos7 test]# getfacl /data/test
getfacl: Removing leading '/' from absolute path names
# file: data/test
# owner: user1
# group: user1
user::rwx
user:user2:rw
group::r-x
mask::rwx
other::r-x
(3) user1在/data/test目录下建立文件a1.sh,a2.sh,a3.sh,a4.sh,设置全部用户都不可删除1.sh、2.sh文件,除了user1及root外,全部用户都不可删除a3.sh、a4.sh
[root@centos7 test]# chattr +i a1.sh a2.sh
[root@centos7 test]# rm a1.sh
rm: remove regular empty file ‘a1.sh’? y
rm: cannot remove ‘a1.sh’: Operation not permitted
[root@centos7 test]# chmod o+x a3.sh a4.sh
[root@centos7 test]# chmod o+t a3.sh a4.sh
(4)、user3增加附加组user1,同时要求user1不能访问/data/test目录及其下所有文件
[root@centos7 ~]# usermod -aG user1 user3
[root@centos7 ~]# id user3
uid=2005(user3) gid=2005(user3) groups=2005(user3),2003(user1)
[root@centos7 ~]# chmod -R u-x /data/test
(5)、清理/data/test目录及其下所有文件的acl权限
[root@centos7 ~]# setfacl -R -b /data/test
[root@centos7 ~]# getfacl /data/test
getfacl: Removing leading '/' from absolute path names
# file: data/test/
# owner: user1
# group: user1
user::rw-
group::r-x
other::r-x