小试牛刀-命令练习(2)
1.显示/etc目录下,以非字母开头,后面跟了一个字母以及其它任意长度任意字符的文件或目录
[root@localhost etc]# cd /etc [root@localhost etc]# mkdir /etc/1c112 [root@localhost etc]# ls -al /etc | grep [^[:alpha:]][[:alpha:]]* drwxr-xr-x 2 root root 4096 Oct 27 10:24 1c112 [root@localhost etc]#
上述问题比较诡异 不在/etc下执行则会出现匹配不到想要的结果 原因待查
[root@localhost etc]# cd [root@localhost ~]# ls -al /etc | grep [^[:alpha:]][[:alpha:]]* total 2436 drwxr-xr-x. 128 root root 12288 Oct 27 11:55 .
2.复制/etc目录下所有以p开头,以非数字结尾的文件或目录到/tmp/mytest1目录中
[root@localhost ~]# cp -r /etc/p*[^[:digit:]] /tmp/mytest1/ [root@localhost ~]# ls /tmp/mytest1/ pam.d pcmcia pm-utils-hd-apm-restore.conf ppp profile pango pinforc pnm2ppa.conf prelink.cache profile.d passwd pki popt.d prelink.conf protocols passwd- plymouth portreserve prelink.conf.d pulse pbm2ppa.conf pm postfix printcap [root@localhost ~]#
3、将/etc/issue文件中的内容转换为大写后保存至/tmp/issue.out文件中
[root@localhost ~]# cat /etc/issue |tr 'a-z' 'A-Z' > /tmp/issue [root@localhost ~]# cat /tmp/issue CENTOS RELEASE 6.9 (FINAL) KERNEL \R ON AN \M [root@localhost ~]#
4.1、创建组distro,其GID为2019;
[root@localhost ~]# groupadd -g 2019 distro [root@localhost ~]# cat /etc/group |grep distro distro:x:2019:
4.2、创建用户mandriva, 其ID号为1005;基本组为distro;
[root@localhost ~]# useradd -u 1005 -g 2019 mandriva [root@localhost ~]# cat /etc/passwd |grep mandriva mandriva:x:1005:2019::/home/mandriva:/bin/bash [root@localhost ~]#
4.3、创建用户mageia,其ID号为1100,家目录为/home/linux;
[root@localhost ~]# useradd -u 1100 -d /home/linux mageia [root@localhost ~]# cat /etc/passwd |grep mageia mageia:x:1100:1100::/home/linux:/bin/bash
4.4、给用户mageia添加密码,密码为mageedu,并设置用户密码7天后过期
[root@localhost ~]# echo 'mageedu' | passwd -x 7 --stdin mageia Adjusting aging data for user mageia. passwd: Success [root@localhost ~]#
4.5、删除mandriva,但保留其家目录;
[root@localhost ~]# userdel mandriva [root@localhost ~]# ls -al /home/mandriva/ total 32 drwx------ 4 1005 distro 4096 Oct 27 15:27 . drwxr-xr-x. 9 root root 4096 Oct 27 15:41 .. -rw-r--r-- 1 1005 distro 18 Mar 23 2017 .bash_logout -rw-r--r-- 1 1005 distro 176 Mar 23 2017 .bash_profile -rw-r--r-- 1 1005 distro 124 Mar 23 2017 .bashrc -rw-r--r-- 1 1005 distro 500 Nov 27 2014 .emacs drwxr-xr-x 2 1005 distro 4096 Nov 12 2010 .gnome2 drwxr-xr-x 4 1005 distro 4096 Jan 10 2017 .mozilla [root@localhost ~]#
4.6、创建用户slackware,其ID号为2002,基本组为distro,附加组peguin;
[root@localhost ~]# useradd -u 2002 -g distro -G peguin slackware [root@localhost ~]# cat /etc/passwd |grep slackware slackware:x:2002:2019::/home/slackware:/bin/bash [root@localhost ~]# cat /etc/group |grep peguin peguin:x:5001:gentoo,slackware [root@localhost ~]#
4.7、修改slackware的默认shell为/bin/tcsh;
[root@localhost ~]# usermod -s /bin/tcsh slackware [root@localhost ~]# cat /etc/passwd |grep slackware slackware:x:2002:2019::/home/slackware:/bin/tcsh [root@localhost ~]#
4.8、为用户slackware新增附加组admins;
[root@localhost ~]# groupadd admins [root@localhost ~]# usermod -aG admins slackware [root@localhost ~]# cat /etc/group |grep slackware peguin:x:5001:gentoo,slackware admins:x:5002:slackware [root@localhost ~]#

浙公网安备 33010602011771号