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

ls -a /etc/ | grep "[[:alpha:]][[:alpha:]].*"

第二周_test




2、复制/etc目录下所有以p开头,以非数字结尾的文件或目录到/tmp/mytest1目录中。

cp -r /etc/p*[^[:digit:]] /tmp/mytest1/

第二周_test_02


3、将/etc/issue文件中的内容转换为大写后保存至/tmp/issue.out文件中

cat /etc/issue| tr a-z A-Z > /tmp/issue.out

第二周_test_03



4、请总结描述用户和组管理类命令的使用方法并完成以下练习:

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

[root@node1 ~]# groupadd -g 2019 distro

第二周_test_04


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

useradd mandriva -u 1005 -g distro (-u指定uid,-g指定组)

第二周_test_05


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

useradd mageia -u 1100 -d /home/linux (-d 指定家目录的地址)

第二周_test_06



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

echo 'mageedu'|passwd --stdin mageia|passwd -n 7 mageia

第二周_test_07



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

userdel mandriva ;(如果要删除家目录,可以使用-r 参数)

第二周_test_08



(6)、创建用户slackware, useradd slackware -u 2002 -g distro -G peguin其ID号为2002,基本组为distro,附加组peguin;


第二周_test_09


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

useradd  -s   /bin/tcsh  slackware 


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

-bash-4.2# groupadd admins
-bash-4.2# usermod -G admins slackware
-bash-4.2# id slackware
uid=1002(slackware) gid=1002(slackware) 组=1002(slackware),1004(admins)
-bash-4.2# cat /etc/passwd|grep slackware
slackware:x:1002:1002::/home/slackware:/bin/bash
-bash-4.2# usermod -s /bin/nologin slackware
-bash-4.2# cat /etc/passwd|grep slackware
slackware:x:1002:1002::/home/slackware:/bin/nologin
-bash-4.2#


5、创建用户user1、user2、user3。在/data/下创建目录test

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

-bash-4.2# useradd user1;useradd user2;useradd user3
-bash-4.2# mkdir -p /data/test/
-bash-4.2# chown user1.user1 /data/test/
-bash-4.2# ls -l /data/
总用量 1
drwxr-xr-x 2 user1 user1 6 12月 13 20:27 test


(2)、在目录属主、属组不变的情况下,user2对文件有读写权限

[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

[root@localhost ~]# setfacl -m u:user2:rwx /data/test/
[root@localhost ~]# su -user2
[user2@localhost ~]$ touch /data/test/2.txt
[user2@localhost ~]$ cd /data/test/
[user2@localhost test]$ ls
总用量 0
-rw-rw-r-- 1 user2 user2 0 12月 13 22:20 2.txt
[root@localhost ~]# getfacl /data/test/
getfacl: Removing leading '/' from absolute path names
# file: data/test/
# owner: user1
# group: user1
user::rwx
user:user2:rwx
group::r-x
mask::rwx
other::r-x

[root@localhost ~]#

(3)、user1在/data/test目录下创建文件a1.sh, a2.sh, a3.sh, a4.sh,设置所有用户都不可删除1.sh,2.sh文件、除了user1及root之外,所有用户都不可删除a3.sh, a4.sh

[root@localhost test]# pwd
/data/test
[root@localhost test]# touch a{1..4}.sh
[root@localhost test]# ls
a1.sh a2.sh a3.sh a4.sh
[root@localhost test]# chattr +i a1.sh a2.sh
[root@localhost test]# lsattr a1.sh a2.sh
----i----------- a1.sh
----i----------- a2.sh
[root@localhost test]# rm -rf a1.sh a2.sh
rm: 无法删除"a1.sh": 不允许的操作
rm: 无法删除"a2.sh": 不允许的操作
[root@localhost test]# chmod o-wx a3.sh a4.sh
[root@localhost test]# ls -ld a3.sh a4.sh
-rw-r--r-- 1 root root 0 12月 13 22:24 a3.sh
-rw-r--r-- 1 root root 0 12月 13 22:24 a4.sh
[root@localhost test]# su - user3
[user3@localhost ~]$ cd /data/test/
[user3@localhost test]$ rm -rf a3.sh a4.sh
rm: 无法删除"a3.sh": 权限不够
rm: 无法删除"a4.sh": 权限不够
[user3@localhost test]$ exit
登出
[root@localhost test]# su - user1
[user1@localhost ~]$ rm -rf /data/test/a{3..4}.sh
[user1@localhost ~]$ ls
[user1@localhost ~]$ ls /data/test/
a1.sh a2.sh

(4)、user3增加附加组user1,同时要求user1不能访问/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:rwx
group::r-x
mask::rwx
other::r-x

[root@localhost ~]# setfacl -m u:user1:--- /data/test/
[root@localhost ~]# setfacl -m u:user2:--- /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:---
group::r-x
mask::r-x
other::r-x

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

[root@localhost ~]# setfacl -R -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

[root@localhost ~]#