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

相关推荐

  • 在linux中创建虚拟网卡(网卡别名)的方法

    由于业务需要,要在单个物理网卡上建立多个虚拟网卡,操作如下:cd /etc/sysconfig/network-scripts/   #进入网卡目录cp ifcfg-eth0 ifcfg-eth0:1   # 复制出ifcfg-eth0:1虚拟网卡vim ifcfg-eth0:1    #配置ifcfg-eth0:1虚…

    Linux干货 2016-09-06
  • 每日一练–8.8 sed,vim

     1 、删除/etc/grub2.conf 文件中所有以空白开头的行行首的空白字符     sed  's/^[[:space:]]//g' /etc grub2.conf  2 、删除/etc/fstab 文件中所有以# 开头,后面至少跟一个空白字符的行的行首的# 和空白字符   &n…

    Linux干货 2016-08-12
  • 10 文本处理のsed狗带

    sed 介绍 工作原理 语法 参数选项:-n, -e, -r, -f, -i 地址定界 编辑命令 查找替换 空间操作 练习 参考文档 sed介绍 sed是一个(stream editor)。         1) :使用sed只能在命令行下输入编辑命令来编辑文…

    Linux干货 2016-08-12
  • linux下的打包与压缩

    linux压缩或解压缩工具有很多,除了已经很少有人使用的compress外,现在常用的还有tar,bzip2,xz 和gzip等,我们来说说它们的用法。 先来说bzip2。bunzip2和bzcat可以由bzip2指定选项来执行同样的结果,这里只介绍bzip2的用法。使用bzip2这个工具创建的文件以.bz2,.bz,.tbz,.tar.bz2或者…

    Linux干货 2017-04-16
  • 第十二周:httpd和lamp

    看了一下作业内容,发现所有的都在51cto上写过了。这里就不在做了。 毕竟当时几篇博客写下来,还是非常繁琐的,不想在写。 文档地址:RHEL6.8编译安装LAMP环境:httpd-2.4+mysql5.6+php5.5;基于LAMP环境部署WordPress: http://afterdawn.blog.51cto.com/7503144/1876171 配…

    Linux干货 2016-12-09
  • Linux文件权限及ACL

    1、文件权限:          文件的权限主要针对三类对象进行定义:                owner:属主,u表示  …

    Linux干货 2016-08-05

评论列表(1条)

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

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