linux学习(2)

发布时间:2022-06-29 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了linux学习(2)脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

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

A1:[root@centos7 ~]# ls -dl /etc/[^[:alpha:]]*

 

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

A2:[root@centos7 ~]# cp -af /etc/p*[^:digIT:]] /tmp/mytest1

 

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

A3:[root@centos7 ~]# tr 'a-z' 'A-Z'< /etc/issue > /tmp/issue.out

   [root@centos7 ~]# cat /tmp/issue.out

   S

   KERNEL R ON AN M

 

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

  (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,并设置不可登陆。

A4:(1):[root@centos7 ~]# groupadd -g 2019 distro

        [root@centos7 ~]# cat /etc/group | tail -1

     distro:x:2019:

   (2):[root@centos7 ~]# useradd -u 1005 -g distro mandriva

         [root@centos7 ~]# id mandriva

    uid=1005(mandriva) gid=2019(distro) groups=2019(distro)

  (3):[root@centos7 ~]# useradd -u 1100 -d /home/linux mageia

     [root@centos7 ~]# id mageia

     uid=1100(mageia) gid=1100(mageia) groups=1100(mageia)

  (4):[root@centos7 ~]# echo "mageedu" | passwd --stdin mageia

     Changing password for user mageia

     passwd: all authentication tokens updated successfully

     [root@centos7 ~]# passwd -x 7 mageia

     Adjusting aging data for user mageia

     passwd: Success

        [root@centos7 ~]# getent shadow mageia

             ;mageia:$6$bNO3uOqM$D8pxt9z0gkO9PsuHUlRPP8DAYmBkJNx3D1SOGO78veNUORwA1AjEw6E.8wsyDv7QUQUgdtZk.d9/b3WjCYEsl/:18686:0:7:7:::

  (5):[root@centos7 ~]# userdel mandriva

     [root@centos7 ~]# ll /home/

     total 12

     drwx------. 2 daiyanfeng  daiyanfeng   4096 Nov   30    00:11    daiyanfeng

     drwx------. 2 mageia        mageia        4096 Nov   29   22:41   linux

     drwx------. 2          1005   distro           4096 Nov   29  22:37    mandriva

  (6):[root@centos7 ~]# groupadd peguin

     [root@centos7 ~]# useradd -u 2002 -g distro -G peguin slackware

     uid=2002(slackware) gid=2019(distro) groups=2019(distro),2020(peguin)

  (7):[root@centos7 ~]# usermod -s /bin/tcsh slackware

     [root@centos7 ~]# getent passwd slackware

     slackware:x:2002:2019::/home/slackware:/bin/tcsh

  (8):[root@centos7 ~]# groupadd admins

     [root@centos7 ~]# usermod -s /bin/false -aG admins slackware

     [root@centos7 ~]# id slackware

     uid=2002(slackware) gid=2019(distro) groups=2019(distro),2020(peguin).2021(admins)

     [root@centos7 ~]# getent passwd slackware

     slackware:x:2002:2019::/home/slackware:/bin/false

 

Q5:创建用户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目录及其下所有文件的acl权限

 

A5:[root@centos7 ~]# useradd user1;useradd user2;useradd user3; mkdir -p /data/test

   [root@centos7 ~]# id user1

   uid=2003(user1) gid=2003(user1) groups=2003(user1)

   [root@centos7 ~]# id user2

   uid=2004(user2) gid=2004(user2) groups=2004(user2)

   [root@centos7 ~]# id user3

   uid=2005(user3) gid=2005(user3) groups=2005(user3)

   [root@centos7 ~]# ll /data

   total 0

   drwxr-xr-x. 2 root root 6 Nov 30 00:21 test

  (1):[root@centos7 ~]# chown -R user1:user1 /data/test

     [root@centos7 ~]# ll /data

     total 0 

     drwxr-xr-x. 2 user1 user1 6 Nov 30 00:24 test

  (2):[root@centos7 ~]# setfacl -m u:user2:rw /data/test

     [root@centos7 ~]# 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::r-x

  (3):[root@centos7 ~]# touch a{1..4}.sh

     [root@centos7 ~]# chattr +i a1.sh a2.sh

     [root@centos7 ~]# lsattr a1.sh a2.sh

     [root@centos7 ~]# rm a1.sh

     rm: remove regular empty file ‘a1.sh’? y

     rm: cannot remove ‘a1.sh’: operation not permitted

     [root@centos7 ~]# chmod o+x a3.sh a4.sh

     [root@centos7 ~]# chmod o+t a3.sh a4.sh

  (4):[root@centos7 ~]# user -aG user1 user3

     [root@centos7 ~]# id user3

     uid=2005(user3) gid=2005(user3) groups=2005(user3),2003(user1)

     [root@centos7 ~]# chmod -R u-x /data/test

  (5):[root@centos7 ~]# setfacl -R -b /data/test

     [root@centos7 ~]# getfacl /data/test

     getfacl: Removing leading '/' from absolute path names

     # file: data/test/

     # owner: user1

     # group: user1

     user::rw-

     group::r-x

     other::r-x

 

脚本宝典总结

以上是脚本宝典为你收集整理的linux学习(2)全部内容,希望文章能够帮你解决linux学习(2)所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。