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

[root@lhq ~]#ls /etc/ | grep "^[^[:alpha:]][[:alpha:]].*$"

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

  • 先列举出来符合要求的文件或目录

    #ls /etc/ |grep "^p.*[^0-9]$"
  • 搭配xargs传参给cp

    xargs -i cp -r {} /tmp/mytest1/

相对路径:

[root@lhq etc]#ls /etc/ |grep "^p.*[^0-9]$" |xargs -i cp -r {} /tmp/mytest1/

绝对路径:

[root@lhq ~]#mkdir /tmp/mytest1
[root@lhq etc]#ls /etc/ |grep "^p.*[^0-9]$" |xargs -i cp -r /etc/{} /tmp/mytest1/

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

[root@lhq ~]#cat /etc/issue | tr "a-z" “A-Z” > /tmp/issue.out
[root@lhq ~]#cat /tmp/issue.out \S
KBOKBI \O LK በ\J

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

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

[root@lhq ~]#groupadd -g 2019 distro
//检验
[root@lhq ~]#cat /etc/group |tail -1
distro:x:2019:

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

[root@lhq ~]#useradd -u 1016 -g distro mandriva
//检验
[root@lhq ~]#id 1016
uid=1016(mandriva) gid=2019(distro) groups=2019(distro)

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

[root@lhq ~]#useradd -u 1100 -d /home/linux mageia
//检验
[root@lhq ~]#cat /etc/passwd |tail -1
mageia:x:1100:1100::/home/linux:/bin/bash

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

[root@lhq ~]#echo mageedu | passwd --stdin mageia | passwd mageia -x 7
Adjusting aging data for user mageia.
passwd: Success
#检验
[root@lhq ~]#cat /etc/shadow |tail -1
mageia:$1$WN/qMbtO$a3ZTk8PLPuEFdeucNrU3E1:18872:0:7:7:::

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

# 查看家目录
[root@lhq ~]#ll /home |grep mandriva
drwx------. 3 mandriva distro 78 Sep 2 10:18 mandriva
#删用户mandriva
[root@lhq ~]#userdel mandriva
# 查看家目录
[root@lhq ~]#ll /home |grep mandriva
drwx------. 3 mandriva distro 78 Sep 2 10:18 mandriva #结论
userdel不做删除家目录操作

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

[root@lhq ~]#useradd -u 2002 -g distro -G peguin slackware
[root@lhq ~]#id 2002
uid=2002(slackware) gid=2019(distro) groups=2019(distro),2020(peguin)

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

[root@lhq ~]#usermod -s /bin/tcsh slackware
#检验
[root@lhq ~]#cat /etc/passwd |tail -1
slackwate:x:2002:2019::/home/slackware:/bin/tcsh

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

[root@lhq ~]#groupadd admins
[root@lhq ~]#usermod -aG admins -s /bin/nologin slackwate

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

[root@lhq ~]mkdir /date/test/
[root@lhq ~]useradd user1;useradd useradd user2;useradd user3

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

[root@lhq ~]#chown user1:user1 /date/test

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

[root@lhq ~]#setfacl -m u:user2:rw- /date/test
#检验
[root@lhq ~]#getfacl /date/test
getfacl: Removing leading '/' from absolute path names
# file: date/test
# owner: user1
# group: user1
user::rwx
user:user2:rw-
group::r-x
mask::rwx
other::r-x

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

[root@lhq ~]#touch /date/test/a{1..4}.sh
[root@lhq test]#cd /date/test
[root@lhq test]#chattr +i a1.sh a2.sh
[root@lhq ~]#chmod 755 /date/test

(4)、user3增加附加组user1,同时要求user1不能访问/data/test目录及其下所有文件

[root@lhq ~]#usermod -aG user1 user3
[root@lhq ~]#chmod u-x /data/test

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

[root@lhq ~]setfacl -b /data/test

llinux_2的更多相关文章

随机推荐

  1. CF612E Square Root of Permutation

    题目分析 我们首先模拟一下题意 假设有一个 \(q _1\) \(p\) \(a_1\) \(a_x\) \(a_{a_1}\) \(a_{a_x}\) \(q\) \(x\) \(a_1\) \(a ...

  2. python_自动查找指定目录下的文件或目录的方法

    代码如下 import os def find_file(search_path, file_type="file", filename=None, file_startswith ...

  3. [Docker] 在CentOS6.8 安装 Docker

    运行docker Linux内核版本需要在3.8以上,针对centos6.5 内核为2.6的系统需要先升级内核.不然会特别卡,退出容器. # 查看当前版本: cat /etc/issue # 导入pu ...

  4. react中使用react-transition-group(CSSTransition)

    https://blog.csdn.net/sophie_u/article/details/80093876

  5. SSR远程密码修改

    第一:输入passwd 第二:填入旧密码 ,随后会有新密码设置 第三:回车两次就行了.

  6. IDEA maven 项目修改代码不生效,mvn clean、install 后才生效

    Maven项目进行修改代码后我们重新运行代码,查看我们target目录下的class文件是否发生了变化.    如何查看class文件,鼠标移到项目,点击右键,然后点击 show in Explore ...

  7. leetcode 51. N皇后 及 52.N皇后 II

    51. N皇后 问题描述 n 皇后问题研究的是如何将 n 个皇后放置在 n×n 的棋盘上,并且使皇后彼此之间不能相互攻击. 上图为 8 皇后问题的一种解法. 给定一个整数 n,返回所有不同的 n 皇后 ...

  8. 【机器学习】GMM和EM算法

    机器学习算法-GMM和EM算法 目录 机器学习算法-GMM和EM算法 1. GMM模型 2. GMM模型参数求解 2.1 参数的求解 2.2 参数和的求解 3. GMM算法的实现 3.1 gmm类的定 ...

  9. 【记录一个问题】go.mod中使用replace后,编译出现神奇的错误:

    biz\child.go:5:2: imported and not used: "xxx.com/start/common/src/polaris" as biz biz\chi ...

  10. Choregraphe 2.8.6.23虚拟Nao机器人Socket is not connected

    Traceback (most recent call last): File "c:/Users/fengmao/OneDrive - University of Wollongong/J ...