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.www58058.com/28247

(0)
~微風~~微風~
上一篇 2016-08-04 14:40
下一篇 2016-08-04 14:41

相關推薦

  • Linux基礎知識之邏輯卷管理器(LVM)

    邏輯卷管理器(LVM)        允許對卷進行方便操作的抽象層,包括重新設定文件系統的大小     允許在多個物理設備間重新組織文件系統將設備指定為物理卷     用一個或者多個物理卷來創建一個卷組  &n…

    Linux干貨 2016-09-01
  • 任務計劃管理

    一:單一工作調度:at命令       列出在指定的時間和日期在計算機上運行的已計劃命令或計劃命令和程序。必須正在運行“計劃”服務才能使用 at 命令。 示例: [root@CentOS 6 ~]#/etc/init.d/atd restart   啟動服務 …

    Linux干貨 2016-09-12
  • N25第三周作業(用戶組,和文本管理)

    列出當前系統 上所有已經登錄用戶的用戶名,注意:同一個用戶登錄多次,則只顯示一次即可. 列出最后登錄到當前系統的用戶相關信息. 命令who查看所有用戶 , tail查看后幾行 取出當前系統上被用戶當作其默認shell的最多那個shell. 命令cut 分割 , -d 指定分隔符,-f指定字段 uniq 顯示或忽略重復行信息   -c:顯示并統計重復…

    Linux干貨 2016-12-19
  • 邏輯卷

    §·邏輯卷管理器LVM介紹 ※·LVM邏輯卷的簡單描述 lvm(logical volume manager 邏輯卷管理器)的可以彈性的調整文件系統的容量,支持任何塊設備,需要使用dm模塊:device mapper設備映射,將一個或多個底層設備組織成一個邏輯設備的模塊。 lvm的重點在于彈性的調整文件系統的容量,而并非在于數據的存儲效率及安全上面…

    Linux干貨 2016-08-30
  • 關于源碼包的基本知識

    關于源碼包的基本知識  §·什么是程序 程序(Program)是為實現特定目標或解決特定問題而用計算機語言編寫的命令序列的集合。為實現預期目的而進行操作的一系列語句和指令。 一般分為系統程序和應用程序兩大類。 程序就是為使電子計算機執行一個或多個操作,或執行某一任務,按序設計的計算機指令的集合。 §·程序包的編譯安裝 ※·為什么需要源碼安裝 1.最…

    Linux干貨 2016-08-24
  • 腳本及變量解析

    bash腳本編程 腳本文件格式: 第一行頂格:#!bin/bash  (shebang) 注釋信息:以#開頭 代碼注釋:好的程序員必備 適量的添加縮進或添加空白行以示分割 語言:編程語言格式:庫,算法和數據結構 編程思想:      能夠把學到的編程語言的語法格式隨時轉換為解決問題的思路     &…

    Linux干貨 2016-08-12
欧美性久久久久