1. 显示/etc目录下,以非字母开头,后面跟了一个字母以及其他任意长度任意字符的文件或目录。
root@centos8 etc]$ls /etc/[^[:alpha:]][[:alpha:]]*
ls: cannot access '/etc/[^[:alpha:]][[:alpha:]]*': No such file or directory
[root@centos8 etc]$ls /data/[^[:alpha:]][[:alpha:]]*
/data/2a3443fdeb.txt
/data/2adir:
[root@centos8 etc]$
2.复制/etc目录下所有以p开头,以非数字结尾的文件或目录到/tmp/mytest目录中。
[root@centos8 etc]$cp -r /etc/p*[^[:digit:]] /tmp/mytest1
[root@centos8 etc]$ls /tmp/mytest1/
pam.d passwd passwd- pki plymouth pm popt.d prelink.conf.d printcap profile profile.d protocols
3. 将/etc/issue文件中的内容转换为大写后保存至/tmp/issue.out文件中。
[root@centos8 etc]$cat /etc/issue
\S
Kernel \r on an \m
terminal: \l
hostname: \m
time: \t
The server will shutdown at 18:30 today
[root@centos8 etc]$cat /etc/issue|tr 'a-z' 'A-Z' >/tmp/issue.out
[root@centos8 etc]$cat /tmp/issue.out
\S
KERNEL \R ON AN \M
TERMINAL: \L
HOSTNAME: \M
TIME: \T
THE SERVER WILL SHUTDOWN AT 18:30 TODAY
4. 请总结描述用户和组管理类命令的使用方法并完成以下练习:
- useradd 添加用户
- usermod 修改用户属性
- passwd 设置用户密码
- chage 设置用户密码策略
- groupadd 添加组
- gpasswd 设置组密码
- groupmems 设置组成员信息
- groupmod 修改用户属性
- chpasswd 设置用户密码
(1),创建组distro,其GID为2019
[root@centos8 etc]$groupadd -g 2019 distro
[root@centos8 etc]$getent group distro
distro:x:2019:
(2),创建用户mandriva,其ID号为1005,基本组为distro
[root@centos8 etc]$useradd -u 1005 -g distro mandriva
[root@centos8 etc]$getent passwd mandriva
mandriva:x:1005:2019::/home/mandriva:/bin/bash
(3),创建用户mageia,其ID号为1100,家目录为/home/linux
[root@centos8 etc]$useradd -u 1100 -d /home/linux mageia
[root@centos8 etc]$getent passwd mageia
mageia:x:1100:1100::/home/linux:/bin/bash
[root@centos8 etc]$
(4),给用户mageia添加密码,密码为mageedu,并设置用户密码7天后过期
[root@centos8 etc]$echo mageedu|passwd --stdin mageia
Changing password for user mageia.
passwd: all authentication tokens updated successfully.
[root@centos8 etc]$chage -M 7 mageia
[root@centos8 etc]$chage -l mageia
Last password change : Dec 08, 2020
Password expires : Dec 15, 2020
Password inactive : Dec 22, 2020
Account expires : Mar 18, 2021
Minimum number of days between password change : 0
Maximum number of days between password change : 7
Number of days of warning before password expires : 7
(5),删除mandriva,并保留其家目录;
[root@centos8 etc]$userdel mandriva
[root@centos8 etc]$ls -al /home/mandriva/
total 12
drwx------ 2 1005 distro 62 Dec 8 09:51 .
drwxr-xr-x. 9 root root 102 Dec 8 09:51 ..
-rw-r--r-- 1 1005 distro 18 Nov 9 2019 .bash_logout
-rw-r--r-- 1 1005 distro 141 Nov 9 2019 .bash_profile
-rw-r--r-- 1 1005 distro 312 Nov 9 2019 .bashrc
(6)创建用户slackware,其ID号为2002,基本组为distro,附加组peguin,
[root@centos8 etc]$useradd -u 2002 -g distro -G peguin slackware
[root@centos8 etc]$id slackware
uid=2002(slackware) gid=2019(distro) groups=2019(distro),2020(peguin)
(7),修改slackware默认shell为/bin/tcsh
[root@centos8 etc]$usermod -s /bin/tcsh slackware
[root@centos8 etc]$getent passwd slackware
slackware:x:2002:2019::/home/slackware:/bin/tcsh
(8),为用户slackware新增附加组admins,并设置不可登录。
[root@centos8 etc]$groupadd admins
[root@centos8 etc]$usermod -aG admins -s /sbin/nologin slackware
[root@centos8 etc]$id slackware
uid=2002(slackware) gid=2019(distro) groups=2019(distro),2020(peguin),2021(admins)
[root@centos8 etc]$getent passwd slackware
slackware:x:2002:2019::/home/slackware:/sbin/nologin
5,创建用户user1,user2,user3。在/data下创建目录test
[root@centos8 etc]$useradd user1
[root@centos8 etc]$useradd user2
[root@centos8 etc]$useradd user3
[root@centos8 etc]$rm -rf /data/*
[root@centos8 etc]$mkdir /data/test
[root@centos8 etc]$
(1),目录/data/test属主,属组为user1,
[root@centos8 etc]$chown user1:user1 /data/test
[root@centos8 etc]$ll -ad /data/test
drwxr-xr-x 2 user1 user1 6 Dec 8 10:26 /data/test
(2),在目录属主,属组不变的情况下,user2对文件有读写权限。
[root@centos8 etc]$setfacl -m g:user2:wr /data/test
[root@centos8 etc]$getfacl /data/test
getfacl: Removing leading '/' from absolute path names
# file: data/test
# owner: user1
# group: user1
user::rwx
group::r-x
group:user2:rw-
mask::rwx
other::r-x
(3),user1在/data/test目录下创建文件a1.sh,a2.sh,a3.sh,a4.sh ,设置所有用户不可以删除a1.sh,a2.sh文件、除了user1及root之外,所有用户都不可以a3.sh,a4.sh
[root@centos8 etc]$chattr +i /data/test/a{1,2}.sh
[root@centos8 etc]$lsattr /data/test/a{1,2}.sh
----i-------------- /data/test/a1.sh
----i-------------- /data/test/a2.sh
[root@centos8 etc]$rm /data/test/a1.sh
rm: remove regular empty file '/data/test/a1.sh'? y
rm: cannot remove '/data/test/a1.sh': Operation not permitted
[root@centos8 etc]$chmod o+t /data/test
[root@centos8 etc]$ls -dl /data/test
drwxrwxr-t+ 2 user1 user1 58 Dec 8 10:33 /data/test
(4),user3增加附加组user1,同时要求user1不能访问/data/test目录下及其下所有文件
[root@centos8 etc]$id user3
uid=2005(user3) gid=2005(user3) groups=2005(user3),2003(user1)
[root@centos8 etc]$setfacl -m g:user1:- /data/test
[root@centos8 etc]$getfacl /data/test
getfacl: Removing leading '/' from absolute path names
# file: data/test
# owner: user1
# group: user1
# flags: --t
user::rwx
group::r-x
group:user1:---
group:user2:rw-
mask::rwx
other::r-x
(5), 清理/data/test目录及其下所有文acl权限
[root@centos8 etc]$setfacl -b /data/test
[root@centos8 etc]$getfacl /data/test
getfacl: Removing leading '/' from absolute path names
# file: data/test
# owner: user1
# group: user1
# flags: --t
user::rwx
group::r-x
other::r-x
[root@centos8 etc]$ls -ld /data/test
drwxr-xr-t 2 user1 user1 58 Dec 8 10:33 /data/test
[root@centos8 etc]$