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)
上一篇 2016-08-04 14:41
下一篇 2016-08-04 14:42

相关推荐

  • Linux基础概念和基础命令

    计算机基础:     一、计算机系统组成               二、冯诺依曼体系              三、服务器存储类…

    Linux干货 2016-07-22
  • httpd配置

    1、Centos7系统下实现httpd-2.2的安装,并分别实现prefork、worker、event等几种工作方式

    2、简述request报文请求方法和状态响应码

    3、详细描述httpd虚拟主机、站点访问控制、基于用户的访问控制、持久链接等应用配置实例

    Linux干货 2018-02-05
  • centos7或centos6中如何编译安装源码程序包

    yum仓库配置、程序的编译安装

    2017-12-02
  • grep、egrep、vim练习

    1、复制/etc/skel目录为/home/tuser1,要求/home/tuser1及内部文件的属组和其它用户均没有任何访问权限。         [root@localhost ~]# install -d -m 600&nb…

    Linux干货 2016-11-18
  • N22-第六周作业

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

    Linux干货 2016-09-26
  • Bash的I/O重定向及管道

    每周更新的博客定时派送啦,本周与大家一起分享的是重定向和管道 首先了解一下 读入数据:Input 输出数据:Output 我们来看一下重定向:  >  覆盖重定向 上面图中 > 文件名     创建空文件 touch 文件名 创建空文件 这两种方法都可以创建一个新的文…

    2017-07-21

评论列表(1条)

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

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