第二周作业
显示/etc目录下,以非字母开头,后面跟了一个字母以及其它任意长度任意字符的文件或目录
[root@ansible etc]# ll [^[:alpha:]][:alpha:]?*
ls: 无法访问[^[:alpha:]][:alpha:]*: 没有那个文件或目录
[root@ansible etc]# touch 1adj356
[root@ansible etc]# ll [^[:alpha:]][:alpha:]?*
-rw-r--r-- 1 root root 0 3月 10 14:00 1adj356
复制/etc目录下所有以p开头,以非数字结尾的文件或目录到/tmp/mytest1目录中。
[root@ansible etc]# mkdir /tmp/mytest1
[root@ansible etc]# cp -r p?*[^[:digit:]] /tmp/mytest1/
[root@ansible etc]# cd /tmp/mytest1/
[root@ansible mytest1]# ll
总用量 52
drwxr-xr-x 2 root root 4096 3月 10 14:08 pam.d
-rw-r--r-- 1 root root 68 3月 10 14:08 papersize
-rw-r--r-- 1 root root 2912 3月 10 14:08 passwd
-rw-r--r-- 1 root root 2869 3月 10 14:08 passwd-
-rw-r--r-- 1 root root 1362 3月 10 14:08 pbm2ppa.conf
-rw-r--r-- 1 root root 2872 3月 10 14:08 pinforc
drwxr-xr-x 12 root root 151 3月 10 14:08 pki
drwxr-xr-x 2 root root 28 3月 10 14:08 plymouth
-rw-r--r-- 1 root root 6300 3月 10 14:08 pnm2ppa.conf
drwxr-xr-x 2 root root 6 3月 10 14:08 popt.d
drwxr-xr-x 2 root root 154 3月 10 14:08 postfix
drwxr-xr-x 3 root root 219 3月 10 14:08 ppp
drwxr-xr-x 2 root root 105 3月 10 14:08 prelink.conf.d
-rw-r--r-- 1 root root 233 3月 10 14:08 printcap
-rw-r--r-- 1 root root 1819 3月 10 14:08 profile
drwxr-xr-x 2 root root 4096 3月 10 14:08 profile.d
-rw-r--r-- 1 root root 6545 3月 10 14:08 protocols
drwxr-xr-x 2 root root 79 3月 10 14:08 pulse
drwxr-xr-x 2 root root 23 3月 10 14:08 purple
drwxr-xr-x 2 root root 35 3月 10 14:08 python
将/etc/issue文件中的内容转换为大写后保存至/tmp/issue.out文件中
[root@ansible mytest1]# cat /etc/issue | tr '[a-z]' '[A-Z]' > /tmp/issue.out
[root@ansible mytest1]# cat /tmp/issue.out
\S
KERNEL \R ON AN \M
4、请总结描述用户和组管理类命令的使用方法并完成以下练习:
创建组distro,其GID为2019
groupadd -g 2019 distro
创建用户mandriva, 其ID号为1005;基本组为distro
useradd -u 1005 -g distro mandriva
创建用户mageia,其ID号为1100,家目录为/home/linux
useradd -u 1100 -d /home/linux mageia
给用户mageia添加密码,密码为mageedu,并设置用户密码7天后过期
echo mageedu | passwd --stdin mageia ; chage -M 7 mageia
删除mandriva,但保留其家目录
userdel mandriva
创建用户slackware,其ID号为2002,基本组为distro,附加组peguin
groupadd peguin ; useradd -u 2002 -g distro -G peguin slackware
修改slackware的默认shell为/bin/tcsh
usermod -s /bin/tcsh slackware
为用户slackware新增附加组admins,并设置不可登陆
groupadd admins ;usermod -G admins -s /sbin/nologin slackware
创建用户user1、user2、user3。在/data/下创建目录test
目录/data/test属主、属组为user1
chown user1 /data/test/ ;chgrp user1 /data/test
在目录属主、属组不变的情况下,user2对文件有读写权限
setfacl -m u:user2:rw /data/test/
user1在/data/test目录下创建文件a1.sh, a2.sh, a3.sh, a4.sh,设置所有用户都不可删除1.sh,2.sh文件、除了user1及root之外,所有用户都不可删除a3.sh, a4.sh
chattr +a a{1..2}.sh
chmod o+t /data/test
user3增加附加组user1,同时要求user1不能访问/data/test目录及其下所有文件
usermod -a -G user1 user3
[root@ansible test]# id user3
uid=2005(user3) gid=2005(user3) 组=2005(user3),2003(user1)
setfacl -m u:user1:--- /data/test/
清理/data/test目录及其下所有文件的acl权限
chattr -a a{1..2}.sh;setfacl -Rb /data/test/
lsattr ;getfacl /data/test/
---------------- ./a1.sh
---------------- ./a2.sh
---------------- ./a3.sh
---------------- ./a4.sh
getfacl: Removing leading '/' from absolute path names
# file: data/test/
# owner: user1
# group: user1
# flags: --t
user::rwx
group::r-x
other::r--

浙公网安备 33010602011771号