一、显示/etc目录下,非字母开头,后面跟了一个字母以及其他任意长度任意字符的文件或目录
命令: ls [^[:alpha:]][[:alpha:]]*
执行结果: 8hr.txt 9wfsd.log
1test:
8A{::
二、复制/etc目录下所有以p开头,以非数字结尾的文件或目录到/tmp/mytest目录中
命令: mkdir /tmp/mytest1
cp -ar /etc/p*[^0-9] /tmp/mytest1
执行结果: [root@bogon ~]# ls /tmp/mytest1
pam.d passwd passwd- pki plymouth pm popt.d postfix ppp prelink.conf.d printcap profile profile.d protocols python
三、将/etc/issue文件中的内容转换为大写后保存至/etc/issue.out文件中
命令 : cat /etc/issue | tr 'a-z' 'A-Z' > /etc/issue.out
执行结果: [root@bogon ~]# cat /etc/issue.out
\S
KERNEL \R ON AN \M
四、用户和组管理类命令的受用方法总结和练习
(1)创建组distro,其GID为2019
(2)创建用户mandriva,其ID号为1005,基本组为distro
(3)创建用户mageia,其ID号为1100,家目录为/home/linux;
(4)给用户mageia添加密码,密码为mageedu,并设置用户密码7天后过期
(5)删除mandriva,但保留其家目录;
(6)创建用户slackware,其ID号为2002,基本组为distro, 附加组peguin;
(7)修改slackware的默认shell为/bin/tcsh;
(8)为用户slackware新增附加组admins, 并设置不可登陆。
命令和执行结果:
(1) groupadd -g 2019 distro
[root@bogon ~]# getent group distro
distro:x:2019:
(2) useradd -u 1005 -g distro mandriva
[root@bogon ~]# getent passwd mandriva
mandriva:x:1005:2019::/home/mandriva:/bin/bash
(3) useradd -u 1100 -d /home/liunx mageia
[root@bogon ~]# getent passwd mageia
mageia:x:1100:1100::/home/liunx:/bin/bash
(4) su mageia
chage -M 7 mageia
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
[root@bogon ~]# su mandriva
[mandriva@bogon root]$
[mandriva@bogon root]$ su mageia
Password:
[mageia@bogon root]$
(5) userdel mandriva
[root@bogon ~]# getent passwd mandriva
[root@bogon ~]# ls /home
liunx mandriva
(6) groupadd peguin
useradd -u 2002 -g distro -G peguin slackware
[root@bogon ~]# getent passwd slackware
slackware:x:2002:2019::/home/slackware:/bin/bash
[root@bogon ~]# getent group peguin
peguin:x:2020:slackware
(7) usermod -s /bin/ctsh slackware
[root@bogon ~]# getent passwd slackware
slackware:x:2002:2019::/home/slackware:/bin/ctsh
(8) usermod -aG admins -s /sbin/nologin slackware
[root@bogon ~]# getent group admins
admins:x:2021:slackware
[root@bogon ~]# su slackware
This account is currently not available.
五、创建用户user1、user2、 user3。 在/data/ 下创建目录test
(1)目录/data/test属主、 属组为user1
(2)在目录属主、属组不变的情况下,user2对文件有读写权限
(3)user1在/data/test目录 下创建文件a1.sh,a2.sh,a3.sh,a4.sh,设置所有用户都不可删
除1.sh, 2.sh文件、 除了user1及root之外,所有用户都不可删除a3.sh,a4.sh
(4)user3增加附加组user1, 同时要求user1不能访问/data/test目录及其下所有文件
(5)清理/data/test目录及 其下所有文件的acI权限
命令和执行结果:
useradd user1
useradd user2
useradd user3
[root@bogon ~]# cat /etc/passwd
user1:x:2003:2003::/home/user1:/bin/bash
user2:x:2004:2004::/home/user2:/bin/bash
user3:x:2005:2005::/home/user3:/bin/bash
kdir /data/test
(1) chown user1:user1 /data/test
[root@bogon ~]# ll /data
total 0
drwxr-xr-x. 2 user1 user1 6 Dec 9 21:33 test
(2) setfacl -m u:user2:rw /data/test
[root@bogon 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::rwx
(3) su user1
mkdir a{1..4}.sh
[user1@bogon test]$ ls
a1.sh a2.sh a3.sh a4.sh
chown user1.user1 a{1..4}.sh
ll /data/test
drwxrwxr-x. 2 user1 user1 6 Dec 9 21:56 a1.sh
drwxrwxr-x. 2 user1 user1 6 Dec 9 21:56 a2.sh
drwxrwxr-x. 2 user1 user1 6 Dec 9 21:56 a3.sh
drwxrwxr-x. 2 user1 user1 6 Dec 9 21:56 a4.sh
chattr +i a1.sh
chattr +i a2.sh
chmod 1000 a{3..4}.sh
[root@localhost ~]# lsattr /data/test
----i----------- /data/test/a1.sh
----i----------- /data/test/a2.sh
---------------- /data/test/a3.sh
---------------- /data/test/a4.sh
[root@localhost ~]# ll /data/test
total 0
drwxrwxr-x. 2 user1 user1 6 Dec 9 21:56 a1.sh
drwxrwxr-x. 2 user1 user1 6 Dec 9 21:47 a2.sh
d--------T. 2 user1 user1 6 Dec 10 23:10 a3.sh
d--------T. 2 user1 user1 6 Dec 10 22:34 a4.sh
(4) groupmems -g user1 -a user3
[root@localhost ~]# id user3
uid=2005(user3) gid=2005(user3) groups=2005(user3),2003(user1)
setfacl -m u:user1:0 /data/test
[root@localhost ~]# getfacl /data/test
getfacl: Removing leading '/' from absolute path names
# file: data/test
# owner: user1
# group: user1
user::rwx
user:user1:---
user:user2:rw-
group::r-x
mask::rwx
other::r-x
(5) setfacl -b /data/test
[root@localhost ~]# 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