1、顯示/etc目錄下,以非字母開(kāi)頭黑低,后面跟了一個(gè)字母以及其他任意長(zhǎng)度任意字符的文件或目錄
[root@CentOS7 ~]# ls -a /etc/ |grep ^[^[:alpha:]].[[:alpha:]]
.pwd.lock
.updated
2、復(fù)制/etc目錄下所有以p開(kāi)頭尽楔,以非數(shù)字結(jié)尾的文件或目錄到/tem/mytest1 目錄中
[root@centos7-master ~]# mkdir -p /tem/mytest1
[root@centos7-master ~]# cd /etc/
[root@centos7-master etc]# cp -a ` ls | grep ^p.*[^[:digit:]]$` /tem/mytest1
[root@centos7-master etc]# ls /tem/mytest1
pam.d passwd- plymouth popt.d ppp printcap profile.d python
passwd pki pm postfix prelink.conf.d profile protocols
3投储、將/etc/issue文件中的內(nèi)容轉(zhuǎn)換為大寫(xiě)后保存至/tmp/issue.out文件中
[root@centos7-master ~]# tr [:lower:] [:upper:] < /etc/issue > /tmp/issue.out
[root@centos7-master ~]# cat /tmp/issue.out
\S
KERNEL \R ON AN \M
4第练、請(qǐng)總結(jié)描述用戶(hù)和組管理類(lèi)命令的使用方法并完成以下練習(xí):
(1)阔馋、創(chuàng)建組distro,其GID為2019;
[root@centos7-master ~]# groupadd distro -g 2019
[root@centos7-master ~]# getent group distro
distro:x:2019:
(2)、創(chuàng)建用戶(hù)mandriva,其ID號(hào)為1005;基本組為distro;
[root@centos7-master ~]# useradd mandriva -u 1005 -g distro
[root@centos7-master ~]# getent passwd mandriva
mandriva:x:1005:2019::/home/mandriva:/bin/bash
(3)娇掏、創(chuàng)建用戶(hù)mageia,其ID號(hào)為1100呕寝,家目錄為/home/linux;
[root@centos7-master ~]# useradd mageia -u 1100 -d /home/linux
[root@centos7-master ~]# getent passwd mageia
mageia:x:1100:1100::/home/linux:/bin/bash
(4)、給用戶(hù)mageia添加密碼婴梧,密碼為mageedu,并設(shè)置用戶(hù)密碼7天后過(guò)期
[root@centos7-master ~]# echo mageia:mageedu |chpasswd
[root@centos7-master ~]# passwd -x 7 mageia
Adjusting aging data for user mageia.
passwd: Success
[root@centos7-master ~]# getent shadow mageia
mageia:$6$nrH9d/K06JmpAPV$4L30icSaWUu1Rt4pc99h1a4Wq7xWKlhtr2mHOaLXDEpkirgNBFe.HcWeSnemE8ZkhlDKG4y8IuJmywxeVLJ9R/:18683:0:7:7:::
(5)下梢、刪除mandriva, 但保留其家目錄;
[root@centos7-master ~]# userdel mandriva
[root@centos7-master ~]# id mandriva
id: mandriva: no such user
[root@centos7-master ~]# ls /home/
linux mandriva
(6)、創(chuàng)建用戶(hù)slackware,其ID號(hào)為2002塞蹭,基本組為distro, 附加組peguin;
[root@centos7-master ~]# groupadd peguin
[root@centos7-master ~]# useradd -u 2002 -g distro -G peguin slackware
[root@centos7-master ~]# id slackware
uid=2002(slackware) gid=2019(distro) groups=2019(distro),2020(peguin)
(7)孽江、修改slackware的默認(rèn)shell為/bin/tcsh;
[root@centos7-master ~]# usermod -s /bin/tcsh slackware
[root@centos7-master ~]# getent passwd slackware
slackware:x:2002:2019::/home/slackware:/bin/tcsh
(8)、為用戶(hù)slackware新增附加組admins,并設(shè)置不可登陸番电。
[root@centos7-master ~]# groupadd admins
[root@centos7-master ~]# usermod -s /bin/false -aG admins slackware
[root@centos7-master ~]# id slackware
uid=2002(slackware) gid=2019(distro) groups=2019(distro),2020(peguin),2021(admins)
[root@centos7-master ~]# getent passwd slackware
slackware:x:2002:2019::/home/slackware:/bin/false
5岗屏、創(chuàng)建用戶(hù)user1、user2漱办、 user3这刷。 在/data/ 下創(chuàng)建目錄test
[root@centos7-master ~]# useradd user1
[root@centos7-master ~]# useradd user2
[root@centos7-master ~]# useradd user3
[root@centos7-master ~]# mkdir -p /data/test
[root@centos7-master ~]# ll -d /data/test/
drwxr-xr-x. 2 root root 6 Feb 25 11:24 /data/test/
(1)、目錄/data/test屬主娩井、 屬組為user1
[root@centos7-master ~]# chown user1:user1 /data/test/
[root@centos7-master ~]# ll -d /data/test/
drwxr-xr-x. 2 user1 user1 6 Feb 25 11:24 /data/test/
(2)暇屋、在目錄屬主、屬組不變的情況下洞辣,user2對(duì)文件有讀寫(xiě)權(quán)限
[root@centos7-master test]# chmod g+w /data/test/
[root@centos7-master test]# gpasswd -a user2 user1
Adding user user2 to group user1
(3)咐刨、user1在/data/test目錄 下創(chuàng)建文件a1.sh,a2.sh,a3.sh,a4.sh,設(shè)置所有用戶(hù)都不可刪
除a1.sh, a2.sh文件、除了user1及root之外扬霜,所有用戶(hù)都不可刪除a3.sh,a4.sh
[user1@centos7-master test]$ touch a{1..4}.sh
[user1@centos7-master test]$ ls
a1.sh a2.sh a3.sh a4.sh
[root@centos7-master test]# chmod o+t /data/test/
[root@centos7-master test]# ls -ld /data/test/
drwxrwxr-t. 2 user1 user1 48 Feb 26 09:46 /data/test/
[root@centos7-master test]# chattr +i a3.sh a4.sh
[root@centos7-master test]# rm -f a3.sh a4.sh
rm: cannot remove ‘a(chǎn)3.sh’: Operation not permitted
rm: cannot remove ‘a(chǎn)4.sh’: Operation not permitted
(4)定鸟、user3增加附加組user1,同時(shí)要求user1不能訪(fǎng)問(wèn)/data/test目錄及其下所有文件
[root@centos7-master test]# gpasswd -a user3 user1
Adding user user3 to group user1
[root@centos7-master test]# chmod u=- /data/test/
(5)、清理/data/test目錄及 其下所有文件的acd權(quán)限
setfacl -R -b /data/test/