8.1-用户和组(作业篇)

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

[root@localhost ~]# tr a-z A-Z </etc/issue > /tmp/issue.out
[root@localhost ~]# cat /tmp/issue.out 
CENTOS RELEASE 6.8 (FINAL)
KERNEL \R ON AN \M

2、将当前系统登录用户的信息转换为大写后保存至/tmp/who.out文件中。

[root@localhost ~]# who | tr a-z A-Z > /tmp/who.out
[root@localhost ~]# cat /tmp/who.out 
ROOT     TTY1         2016-07-21 03:43
ROOT     PTS/0        2016-07-21 03:45 (10.1.252.7)

3、一个linux用户给root发邮件,要求邮件标题为”help”,邮件正文如下:Hello, I am 用户名,the system version is here,pleasehelp

 me to check it ,thanks!操作系统版本信息。

普通用户:
[cej@localhost ~]$ echo "Hello,i am `whoami`,the system version is here,pleasehelp me to check it ,thanks! `uname -r`"| mail -s Hello root
root:
[root@localhost ~]# mail
Heirloom Mail version 12.4 7/29/08.  Type ? for help.
"/var/spool/mail/root": 1 message 1 new
>N  1 cej@localhost.locald  Thu Jul 21 03:53  18/687   "Hello"
& 1
Message  1:
From cej@localhost.localdomain  Thu Jul 21 03:53:17 2016
Return-Path: <cej@localhost.localdomain>
X-Original-To: root
Delivered-To: root@localhost.localdomain
Date: Thu, 21 Jul 2016 03:53:17 +0800
To: root@localhost.localdomain
Subject: Hello
User-Agent: Heirloom mailx 12.4 7/29/08
Content-Type: text/plain; charset=us-ascii
From: cej@localhost.localdomain
Status: R
Hello,i am cej,the system version is here,pleasehelp me to check it ,thanks! 2.6.32-642.el6.x86_64

4、将/root/下文件列表,显示成一行,并文件名之间用空格隔开。

[root@localhost ~]# ls /root/
anaconda-ks.cfg  install.log  install.log.syslog  公共的  模板  视频  图片  文档  下载  音乐  桌面

ls虽然输出至屏幕显示在一行,观察输出至文件得知实际上是分行显示

[root@localhost ~]# ls /root/ > /tmp/root.txt
[root@localhost ~]# cat /tmp/root.txt 
anaconda-ks.cfg
install.log
install.log.syslog
公共的
模板
视频
图片
文档
下载
音乐
桌面

[root@localhost ~]# ls /root/|tr ["\n"] ["\040"]
anaconda-ks.cfg install.log install.log.syslog 公共的 模板 视频 图片 文档 下载 音乐 桌面 [root@localhost ~]#

5、file1文件的内容为:”1 2 3 4 5 6 7 8 9 10” 计算出所有数字的总和。

[root@localhost ~]# cat file1 
1 2 3 4 5 6 7 8 9 10
[root@localhost ~]# tr ' ' '+' <file1 
1+2+3+4+5+6+7+8+9+10
[root@localhost ~]# tr ' ' '+' <file1 |bc
55

6、删除Windows文本文件中的'^M'字符


[root@localhost ~]# cat -A windows.txt 
a^M$
a^M$
a^M$
a^M$
a^M$
[root@localhost ~]# tr -d '\015' <file1 
1 2 3 4 5 6 7 8 9 10
[root@localhost ~]# tr -d '^M' <file1 
1 2 3 4 5 6 7 8 9 10

 

7、处理字符串“xt.,l 1 jr#!$mn2 c*/fe3 uz4”,只保留其中的数字和空格。

[root@localhost ~]# echo 'xt.,l 1 jr#!$mn2 c*/fe3 uz4' | tr -cd '[0-9][ ]'
 1 2 3 4

 

8、将PATH变量每个目录显示在独立的一行。

[root@localhost ~]# echo $PATH | tr ':' '\n'
/usr/lib64/qt-3.3/bin
/usr/local/sbin
/usr/local/bin
/sbin
/bin
/usr/sbin
/usr/bin
/root/bin

9、删除指定文件的空行。

[root@localhost ~]# cat line.txt 
aaaaaaaaaaaa

bbbbbbbbbbbb

vvvvvvvvvvvv
[root@localhost ~]# cat line.txt| tr -s '\n'  
aaaaaaaaaaaa
bbbbbbbbbbbb
vvvvvvvvvvvv

10、将文件中每个单词(字母)显示在独立的一行,并无空行。

[root@localhost ~]# cat /etc/issue | tr -s ' ' '\n'
CentOS
release
6.8
(Final)
Kernel
\r
on
an
\m

11、创建用户gentoo,附加组为bin和root,默认shell为/bin/csh,注释信息为"Gentoo Distribution"

[root@localhost ~]# groups bin
bin : bin daemon sys
[root@localhost ~]# groups root
root : root
[root@localhost ~]# useradd -s /bin/csh -c "Gentoo Distribution" -G bin,root gentoo
[root@localhost ~]# tail -1 /etc/passwd
gentoo:x:501:501:Gentoo Distribution:/home/gentoo:/bin/csh
[root@localhost ~]# grep -E "(^bin|^root)" /etc/group
root:x:0:gentoo
bin:x:1:bin,daemon,gentoo

2、创建下面的用户、组和组成员关系
(1)名字为admins 的组
(2)用户natasha,使用admins 作为附属组
(3)用户harry,也使用admins 作为附属组
(4)用户sarah,不可交互登录系统, 且不是admins 的成员,natasha, harry, sarah密码都是centos

[root@localhost ~]# groupadd admins
[root@localhost ~]# tail -1 /etc/group
admins:x:502:
[root@localhost ~]# useradd -G admins natasha
[root@localhost ~]# useradd -G admins harry
[root@localhost ~]# tail -3 /etc/group
admins:x:502:natasha,harry
natasha:x:503:
harry:x:504:
[root@localhost ~]# useradd -s /sbin/nologin sarah
[root@localhost ~]# echo "centos" | passwd --stdin natasha
更改用户 natasha 的密码 。
passwd: 所有的身份验证令牌已经成功更新。
[root@localhost ~]# echo "centos" | passwd --stdin harry
更改用户 harry 的密码 。
passwd: 所有的身份验证令牌已经成功更新。
[root@localhost ~]# echo "centos" | passwd --stdin sarah
更改用户 sarah 的密码 。
passwd: 所有的身份验证令牌已经成功更新。

 


1、创建testuser uid 1234,主组:bin,辅助组:root,ftp,shell:/bin/csh home:/testdir/testuser

[root@localhost ~]# mkdir /testdir
[root@localhost ~]# useradd testuser -u 1234 -g bin -G root,ftp -s /bin/csh -d /testdir/testuser

2、修改testuser uid:4321,主组:root,辅助组:nobody,loginname:test,home:/home/test 家数据迁移

[root@localhost ~]# usermod -u 4321 -g root -G nobody -l test -md /home/test testuser 
[root@localhost ~]# id test
uid=4321(test) gid=0(root) 组=0(root),99(nobody)
[root@localhost ~]# getent passwd test
test:x:4321:0::/home/test:/bin/csh

3、批量创建帐号:user1…user10
(1)、uid:3000-3009,shell:/bin/csh,home:/testdir/username
(2)、passwd:usernamepass
(3)、注意家目录相关配置,使用户正常登录

[root@localhost ~]# cat user.txt 
user1:!!:3000:3000::/testdir/user1:/bin/csh
user2:!!:3001:3001::/testdir/user2:/bin/csh
user3:!!:3002:3002::/testdir/user3:/bin/csh
user4:!!:3003:3003::/testdir/user4:/bin/csh
user5:!!:3004:3004::/testdir/user5:/bin/csh
user6:!!:3005:3005::/testdir/user6:/bin/csh
user7:!!:3006:3006::/testdir/user7:/bin/csh
user8:!!:3007:3007::/testdir/user8:/bin/csh
user9:!!:3008:3008::/testdir/user9:/bin/csh
user10:!!:3009:3009::/testdir/use10:/bin/csh
[root@localhost ~]# cat passwd.txt 
user1:user1pass
user2:user2pass
user3:user3pass
user4:user4pass
user5:user5pass
user6:user6pass
user7:user7pass
user8:user8pass
user9:user9pass
user10:user10pass
[root@localhost ~]# newuser user.txt
[root@localhost ~]# cat passwd.txt | chpasswd

[root@localhost ~]# tail -10 /etc/passwd
user1:x:3000:3000::/testdir/user1:/bin/csh
user2:x:3001:3001::/testdir/user2:/bin/csh
user3:x:3002:3002::/testdir/user3:/bin/csh
user4:x:3003:3003::/testdir/user4:/bin/csh
user5:x:3004:3004::/testdir/user5:/bin/csh
user6:x:3005:3005::/testdir/user6:/bin/csh
user7:x:3006:3006::/testdir/user7:/bin/csh
user8:x:3007:3007::/testdir/user8:/bin/csh
user9:x:3008:3008::/testdir/user9:/bin/csh
user10:x:3009:3009::/testdir/use10:/bin/csh
[root@localhost ~]# tail -10 /etc/shadow
user1:$6$9fYDi/ka1/Z/$NrWYcHvh4zvoaemMPU1GwNBNwe94LoS.bTJzcTYZkMK6LAjUBp4PkY9WnKn8/0MPtXEdnMgHwCYe.u0g/7Qpy/:17002:0:99999:7:::
user2:$6$S5.GJ/nwdsxNj2A9$J0Eb1QwtgoxzuxkRf4Pr/e2lF/.E6T111O1s9.VpLfS78HZMKocuoS3F2Vw3v0ilmPJZFwyIzhCK8O7ZzQLk2/:17002:0:99999:7:::
user3:$6$sZs15/qhGLD$3I0n8vPYACVYEuDcypd/veuTXGsay7U6DYKq6ucKHcB.LEG0M3z5G1umy3GwlCth9RQWACmrOr/bcfrIRalUj1:17002:0:99999:7:::
user4:$6$rBLHbzMoIA/d$Scv/W4M1rh4L7os43BQygRVaNeLgAQLZ5rcmShOiSzFiAAu3Poe6HpXLpHf7WcxD5OjY6Ae.b0EsDI6RI3z9c1:17002:0:99999:7:::
user5:$6$r6wYO/ny1E31$mhpih1Wy56xk1OR6lXFTOn1sOUhazoTy5va7LXmKDRnFxe8cO5be.VLVWXcO6sDFZWl1i4DydIRzVLvirB0A01:17002:0:99999:7:::
user6:$6$Xbdfi/6pUJI/tX$EzjSufBp6L669jc.fFMMmGIf6SZg5IHFQWbBtRBd8gcMgwiAn6mQAYuM2gbwHnVBwpozLYsLESMAmB8tOL58U1:17002:0:99999:7:::
user7:$6$A38dq/2fvTr/$NfCir91Igb03gseViQm0UTY4CNZdnfkLgPcit2Q9Ey643wmzNc1V3hSBJa0eTGZCRWCpQOQ.1H8zVlsW0Er5I/:17002:0:99999:7:::
user8:$6$IyWsW/bB1$bpcadfLAT8zybea0o.JTnHo4D3XlaYCQP2uaoKzIPW0dDqBXIh86ewksdZHM4EADqPjcQg.yOyk3ktziBIJYc0:17002:0:99999:7:::
user9:$6$N1jQs/D42PH$l/aR0nCJX3i4s5zoKMgLN1U.HTqIlR/YbFwY5YqTVFZBrlTKiFDE9Z9QvQ3cei3psu.jaX026.pFOgfXOxDM01:17002:0:99999:7:::
user10:$6$YiHga/zg5Qs/zOjS$9uKAP3FMlx/ZwUYyQJHXBrGuor/CaMfk4SUTQkXn1Af08Ler7p6nv55rMSX.oDsJ2FWFCEz/WsOiwYd/oCmn0/:17002:0:99999:7:::

[root@localhost ~]# cp -r /etc/skel/.[^.]* /testdir/use1
[root@localhost ~]# cp -r /etc/skel/.[^.]* /testdir/use2
[root@localhost ~]# cp -r /etc/skel/.[^.]* /testdir/use3
[root@localhost ~]# cp -r /etc/skel/.[^.]* /testdir/use4
[root@localhost ~]# cp -r /etc/skel/.[^.]* /testdir/use5
[root@localhost ~]# cp -r /etc/skel/.[^.]* /testdir/use6
[root@localhost ~]# cp -r /etc/skel/.[^.]* /testdir/use7
[root@localhost ~]# cp -r /etc/skel/.[^.]* /testdir/use8
[root@localhost ~]# cp -r /etc/skel/.[^.]* /testdir/use9
[root@localhost ~]# cp -r /etc/skel/.[^.]* /testdir/use10

[c:\~]$ ssh 
[c:\~]$ Connecting to 10.1.252.66:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
[user1@localhost ~]$ 
正常登陆!










原创文章,作者:M20-1--孔祥文,如若转载,请注明出处:http://www.178linux.com/27179

(0)
M20-1--孔祥文M20-1--孔祥文
上一篇 2016-08-04 14:41
下一篇 2016-08-04 14:41

相关推荐

  • 简单救援模式应用

                                  …

    2017-08-12
  • RHCE系列之ntp服务器—-实践篇

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://nolinux.blog.51cto.com/4824967/1319520 上篇Linux实战部署系列之ntp服务器—-理论篇为大家介绍时间的相关概念和ntp的原理,本篇博文将带大家一起部署生产环境中实现简单…

    Linux干货 2016-08-15
  • pxe和dhcp服务——引导安装操作系统

    BootStraping:系统提供(OS Provision) pxe –> preboot excution environment, Intel cobbler –> Cobbler is a network install server.  Cobbler supports PXE, ISO virtual…

    Linux干货 2016-11-05
  • 马哥教育网络班第21期+第六周课程作业

    1、复制/etc/rc.d/rc.sysinit文件至/tmp目录,将/tmp/rc.sysinit文件中的1、以至少一个空白字符开头的行的行首加#; :%s@^[[:space:]]\+@#@   2、复制/boot/grub/grub.conf至/tmp目录中,删除/tmp/grub.conf文件中的行首的空白字符; :%s@^[[:space…

    Linux干货 2016-08-22
  • 第八周作业

    1. 写一个脚本,使用ping命令探测172.16.250.1-172.16.250.254之间的所有主机的在线状态;     在线的主机使用绿色显示;     不在线的主机使用红色显示; #!/bin/bash # for i in {1..254};do         pi…

    Linux干货 2017-02-24
  • N26-博客作业-week10

    1、请详细描述CentOS系统的启动流程(详细到每个过程系统做了哪些事情) 2、为运行于虚拟机上的CentOS 6添加一块新硬件,提供两个主分区;  (1) 为硬盘新建两个主分区;并为其安装grub;  (2) 为硬盘的第一个主分区提供内核和ramdisk文件; 为第二个分区提供rootfs;  (3) 为rootfs提供bas…

    2017-04-09

评论列表(1条)

  • 马哥教育
    马哥教育 2016-08-04 15:17

    作业完成的很好,排版也很用心,再接再厉。