8.1_Linux习题和作业

7.28 作业

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

1
# cat /etc/issue | tr 'a-z' 'A-Z'whoi > /tmp/issue.out


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

1
# who am i | tr 'a-z' 'A-Z' > /tmp/who.out

3、一个linux用户给root发邮件,要求邮件标题为”help”,邮件正文如下:

Hello, I am 用户名,the system version is here,pleasehelp me to check it ,thanks!

操作系统版本信息

1
2
3
4
5
6
[w@centos6 ~]$ mail -s help root <<eof
> Hellp, I am `whoami`
> the system version is here
> please help me to check it,thanks!
> `lsb_release`
> eof
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
[root@centos6 ~]# mail
Heirloom Mail version 12.4 7/29/08.  Type ? for help.
"/var/spool/mail/root": 1 message 1 new
>N  1 w@centos6.localdomai  Mon Aug  1 20:13  21/799   "help"
& 1
Message  1:
From w@centos6.localdomain  Mon Aug  1 20:13:18 2016
Return-Path: <w@centos6.localdomain>
X-Original-To: root
Delivered-To: root@centos6.localdomain
Date: Mon, 01 Aug 2016 20:13:17 +0800
To: root@centos6.localdomain
Subject: help
User-Agent: Heirloom mailx 12.4 7/29/08
Content-Type: text/plain; charset=us-ascii
From: w@centos6.localdomain
Status: R
 
Hellp, I am w
the system version is here
please help me to check it,thanks!
LSB Version:   :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.
0-noarch
 
&


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

1
# cat /root | tr '\n' ' '


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

1
# echo "1 2 3 4 5 6 7 8 9 10" | tr ' ' '+' |bc


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

1
2
3
# cat a.txt |tr -d '^M'
# cat a.txt |tr -d '\015'
# cat a.txt |tr -d '\r'


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

1
# echo 'xt.,l 1 jr#!$mn2 c*/fe3 uz4' | tr -d '[:punct:]' | tr -d 'a-z'


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

1
# echo $PATH | tr ':' '\n'


9、删除指定文件的空行

1
2
# cat a.txt |tr -d '\n'  #不是正确答案 
# cat a.txt |tr -s '\n'  #不是正确答案


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

1
# cat /etc/init.d/functions | tr -cs '[:alpha:]' '\n'


8.1习题

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

1
# useradd -s /bin/csh -c "Gentoo Distribution" -G bin,root gentoo

2、创建下面的用户、组和组成员关系

名字为admins 的组

用户natasha,使用admins 作为附属组

用户harry,也使用admins 作为附属组

用户sarah,不可交互登录系统,且不是admins 的成员,natasha,harry,sarah密码都是centos

1
2
3
4
5
6
7
# groupadd admins
# useradd -G admins natasha
# useradd -G admin harry
# useradd -s /sbin/nologin sarah
# echo "centos" | passwd --stdin sarah
# echo "centos" | passwd --stdin harry
# echo "centos" | passwd --stdin natasha

8.1 作业

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

1
# useradd -u 1234 -g bin -G root,ftp -s /bin/csh -d /testdir/testuser testuser

2、修改testuser uid:4321,主组:root,辅助组:nobody,loginname:test,home:/home/test 家数据迁移注意家目录相关配置,使用户正常登录

1
# usermod -u 4321 -g root -G nobody -l test -d /home/test -m testuser

3、批量创建帐号:user1…user10 ,uid:3000-3009,shell:/bin/csh,home:/testdir/username

passwd:usernamepass 注意家目录相关配置,使用户正常登录

1
# vim userfile

wKiom1efSSzSmuawAABLR1XVsBM522.png

1
# vim passfile

wKioL1efSVSRPCbMAAAN9V5wOAo301.png 

1
2
3
4
5
6
7
8
9
10
11
12
# newusers userfile
# cat passfile |chpasswd
# \cp -r /etc/skel/.[^.]* /testdir/user1
# \cp -r /etc/skel/.[^.]* /testdir/user2
# \cp -r /etc/skel/.[^.]* /testdir/user3
# \cp -r /etc/skel/.[^.]* /testdir/user4
# \cp -r /etc/skel/.[^.]* /testdir/user5
# \cp -r /etc/skel/.[^.]* /testdir/user6
# \cp -r /etc/skel/.[^.]* /testdir/user7
# \cp -r /etc/skel/.[^.]* /testdir/user8
# \cp -r /etc/skel/.[^.]* /testdir/user9
# \cp -r /etc/skel/.[^.]* /testdir/user10

原创文章,作者:~微风~,如若转载,请注明出处:http://www.178linux.com/28247

(0)
~微风~~微风~
上一篇 2016-08-04
下一篇 2016-08-04

相关推荐

  • N25-第九周作业

    1、写一个脚本,判断当前系统上所有用户的shell是否为可登录shell(即用户的shell不是/sbin/nologin);分别统计这两类用户的个数;通过字符串比较来实现; #!/bin/bash     echo “可登录类型有有$(awk -F: ‘/[^\<nologin\>…

    Linux干货 2017-03-11
  • 第三周作业

    第三周作业

    Linux干货 2017-12-19
  • http请求过程

    1、浏览器根据访问的域名找到其IP地址。DNS查找过程如下: 1.浏览器缓存:浏览器会缓存DNS记录一段时间。 2.系统缓存:如果在浏览器缓存里没有找到需要的域名,浏览器会查系统缓存中的记录。 3.路由器缓存:如果系统缓存也没找到需要的域名,则会向路由器发送查询请求。 4.ISP DNS缓存:如果依然没找到需要的域名,则最后要查的就是ISP缓存DNS的服务器…

    Linux干货 2017-10-23
  • linux时间

    linux有两个时间:     系统时间和硬件时间 系统时间: 最简单的使用date命令显示当前系统的时间,命令行输入date。 # date Thu Jun  2 17:11:48 CST 2016 date的具体使用方式:     1. date格式显示:date …

    Linux干货 2016-06-03
  • 磁盘管理及shell脚本编程练习

    1、创建一个10G分区,并格式为ext4文件系统 a) 要求其block大小为2048,预留空间百分比为2,卷标为MYDATA,默认挂载属性包含acl; ~]# mke2fs –t ext4 –b 2048 –m 2 –L MYDATA  /dev/sda3 b) 挂载至/data/madata目录,要求挂载时禁止程序自动运行,且不更新文件的访问时间戳; ~…

    2017-11-15
  • 计算机基础及Linux基础概述

    马哥教育网络班23期+第1周课程练习 计算机基础及Linux基础概述 一、计算机组成及其功能 1.1、概述     计算机,computer 我们在中国都称它为电脑,其实我们个人使用的计算机只是计算机家族的一部分,计算机分很多种,小型机,中型机,大型机,工作站,还有PC机,等等,其实我们家庭中使用的只能算是PC机,其实…

    Linux干货 2016-09-15