Linux third week homework

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

[root@centos7 ~]#cd /etc
[root@centos7 etc]#touch 1a
[root@centos7 etc]#ls /etc/[^a-Z][a-Z]*
/etc/1a

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

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

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

[root@centos7 etc]#cat /etc/issue
Time at /t
Terminal in/l

\S
Kernel \r on an \m
[root@centos7 etc]#cat /etc/issue|tr 'a-z' 'A-Z' > /tmp/issue.out
[root@centos7 etc]#cat /tmp/issue.out
TIME AT /T
TERMINAL IN/L

\S
KERNEL \R ON AN \M

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


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

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

【-g】指定工作组的GID;


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

[root@centos7 ~]#useradd -u 1005 -g distro mandriva
[root@centos7 ~]#id mandriva
uid=1005(mandriva) gid=2019(distro) groups=2019(distro)

【-u】指定用户的uid;
【-g】指定用户的组;
【-G】指定用户的附加组;
【-s】指定用户登录的shell;
【-c】指定一段注释性描述;
【-d】指定用户的主目录,如果主目录不存在,同时使用-m,创建主目录;


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

[root@centos7 ~]#useradd -u 1100 -d /home/linux mageia
[root@centos7 ~]#id mageia
uid=1100(mageia) gid=1100(mageia) groups=1100(mageia)
[root@centos7 ~]#ls /home/
andy  linux  mandriva

【useradd -u】指定用户的uid;
【useradd -d】指定用户家目录;


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

[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

 


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

[root@centos7 ~]#userdel mandriva 
[root@centos7 ~]#ls /home/
andy  linux  mandriva


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

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

【useradd -u】指定uid;
【useradd -g】指定组;
【useradd -G】指定附加组;


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

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

【usermod -s】修改用户的shell;
【usermod -u】修改用户的uid;
【usermod -L】锁定用户密码,使密码无效;


   (8)、为用户slackware新增附加组admins;

[root@centos7 ~]#groupadd admins
[root@centos7 ~]#id slackware
uid=2002(slackware) gid=2019(distro) groups=2019(distro),2020(peguin)
[root@centos7 ~]#usermod -aG admins slackware 
[root@centos7 ~]#id slackware
uid=2002(slackware) gid=2019(distro) groups=2019(distro),2020(peguin),2021(admins)

【usermod -a】在原来所属组的基础上追加;
【usermod -G】为用户添加附加组;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值