标签:有用 poll Owner new out 默认 其它 alpha ack
1、显示/etc目录下,以非字母开头,后面跟了一个字母以及其它任意长度任意字符的文件或目录
lime@ubuntu1804:/etc$ sudo touch 123abc.txt
lime@ubuntu1804:/etc$ ls /etc/[^[:alpha:]]*
/etc/123abc.txt
2、复制/etc目录下所有以p开头,以非数字结尾的文件或目录到/tmp/mytest1目录中
lime@ubuntu1804:~$ sudo cp -rp /etc/p*[^[:digit:]] /tmp/mytest1
lime@ubuntu1804:~$ ll /tmp/mytest1/
total 48
-rw-r--r-- 1 root root 552 Apr 5 2018 pam.conf
drwxr-xr-x 2 root root 4096 Feb 6 22:20 pam.d
-rw-r--r-- 1 root root 1645 Mar 3 21:40 passwd
-rw-r--r-- 1 root root 1608 Feb 18 21:42 passwd-
drwxr-xr-x 4 root root 4096 Feb 2 00:32 perl
drwxr-xr-x 3 root root 4096 Feb 2 00:31 pm
drwxr-xr-x 2 root root 4096 Feb 2 00:35 pollinate
-rw-r--r-- 1 root root 350 Feb 2 00:33 popularity-contest.conf
drwxr-xr-x 7 root dip 4096 Feb 6 22:20 ppp
-rw-r--r-- 1 root root 623 Feb 17 21:27 profile
drwxr-xr-x 2 root root 4096 Feb 17 20:04 profile.d
-rw-r--r-- 1 root root 2932 Dec 26 2016 protocols
3、将/etc/issue文件中的内容转换为大写后保存至/tmp/issue.out文件中
lime@ubuntu1804:~$ sudo tr ‘a-z‘ ‘A-Z‘ < /etc/issue >/tmp/issue.out
lime@ubuntu1804:~$ cat /tmp/issue.out
UBUNTU 18.04.4 LTS \N \L
4、总结描述用户和组管理类命令的使用方法
(1)创建组distro,其GID为2019
lime@ubuntu1804:~$ groupadd -g 2019 -r distro
lime@ubuntu1804:~$ getent group distro
distro:x:2019:
(2)创建用户mandriva,其ID号为1005;基本组为distro;
lime@ubuntu1804:~$ sudo useradd mandirva -g 2019 -u 1005 -m
lime@ubuntu1804:~$ getent passwd mandirva
mandirva:x:1005:2019::/home/mandirva:/bin/sh
(3)创建用户mageia,其ID号为1100,家目录为/home/linux
lime@ubuntu1804:~$ sudo useradd mageia -u 1100 -d /home/linux -m
lime@ubuntu1804:~$ getent passwd mageia
mageia:x:1100:1100::/home/linux:/bin/s
(4)给用户mageia添加密码,密码为mageedu,并设置用户密码7天后过期
lime@ubuntu1804:~$ sudo passwd mageia
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
lime@ubuntu1804:~$ sudo chage -I 7 mageia
lime@ubuntu1804:~$ sudo getent shadow mageia
mageia:$6$RwUHXdYP$oeBy4PQZuoRBMbAGiE0gb/FtHnDIfYY9XSrVetc2RlW/AMKkubeqsLsCwZJnNYi/OsPmEI70iBinOOsXCV7jM1:18691:0:99999:7:7::
(5)删除mandriva,但保留其家目录;
root@ubuntu1804:~# userdel mandirva
root@ubuntu1804:~# ll /home/
total 16
drwxr-xr-x 4 root root 4096 Mar 5 23:03 ./
drwxr-xr-x 25 root root 4096 Mar 3 23:56 ../
drwxr-xr-x 5 lime lime 4096 Mar 5 21:17 lime/
drwxr-xr-x 2 1005 distro 4096 Mar 5 23:03 mandirva/
(6)创建用户slackware,其ID号为2002,基本组为distro,附加组peguin;
lime@ubuntu1804:~$ sudo groupadd -g 2020 -r peguin
lime@ubuntu1804:~$ sudo groupmems -a slackware -g peguin
Password:
lime@ubuntu1804:~$ id slackware
uid=2002(slackware) gid=2019(distro) groups=2019(distro),0(root),2020(peguin)
(7)修改slackware的默认shell为/bin/tcsh--ubuntu-没有tcsh
lime@ubuntu1804:~$ sudo chsh -s /bin/sh slackware
(8)为用户slackware新增附加组admins,并设置不可登陆
lime@ubuntu1804:~$ sudo groupadd -g 2021 -r admins
lime@ubuntu1804:~$ sudo groupmems -a slackware -g admins
lime@ubuntu1804:~$ sud chsh -s /bin/nologin slackware
lime@ubuntu1804:~$ sudo passwd slackware
lime@ubuntu1804:~$ su slackware
Password:
lime@ubuntu1804:~$
5、创建用户user1, user2, user3,在/data/下创建目录test
(1)目录/data/test属主、属组为user1
lime@ubuntu1804:/data$ sudo chown user1 /data/test
lime@ubuntu1804:/data$ sudo chgrp user1 /data/test/
lime@ubuntu1804:/data$ ll
total 4
drwxr-xr-x 2 user1 user1 4096 Mar 5 23:24 test
(2)在目录属主、属组不变的情况下, user2对文件有读写权限
lime@ubuntu1804:/data$ sudo chmod a=rwx test/
(3)user1在/data/test目录下创建文件a1.sh, a2.sh, a3.sh,a4.sh,设置所有用户都不可删
除a1.sh, a2.sh文件、除了user1及root之外,所有用户都不可删除a3.sh, a4.sh
lime@ubuntu1804:/data/test$ touch a{1..4}.sh
lime@ubuntu1804:/data/test$ ll
total 0
-rw-rw-r-- 1 lime lime 0 Mar 5 23:32 a1.sh
-rw-rw-r-- 1 lime lime 0 Mar 5 23:32 a2.sh
-rw-rw-r-- 1 lime lime 0 Mar 5 23:32 a3.sh
-rw-rw-r-- 1 lime lime 0 Mar 5 23:32 a4.sh
lime@ubuntu1804:/data/test$ sudo chattr +i a1.sh a2.sh
lime@ubuntu1804:/data/test$ rm a1.sh
rm: cannot remove ‘a1.sh‘: Operation not permitted
lime@ubuntu1804:/data/test$ lsattr a1.sh
----i---------e--- a1.sh
lime@ubuntu1804:/data/test$ chmod a+t a4.sh a3.sh
(4)user3增加附加组user1,同时要求user1不能访问/data/test目录及其下所有文件
lime@ubuntu1804:~$ sudo usermod -aG user1 user3
lime@ubuntu1804:~$ id user3
uid=2005(user3) gid=2005(user3) groups=2005(user3),2003(user1)
lime@ubuntu1804:~$ sudo setfacl -m u:user1:--- /data/test/
(5)清理/data/test目录及其下所有文件的acl权限
lime@ubuntu1804:/data$ sudo setfacl -b test/
lime@ubuntu1804:/data/test$ sudo chattr -i a1.sh a2.sh
lime@ubuntu1804:/data/test$ getfacl a1.sh
# file: a1.sh
# owner: lime
# group: lime
user::rw-
group::rw-
other::r--
标签:有用 poll Owner new out 默认 其它 alpha ack
原文地址:https://www.cnblogs.com/limeliu/p/14483724.html