歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux技術

7月28號作業

1、將/etc/issue文件中的內容轉換為大寫後保存至/tmp/issue.out文件中

[root@localhost ~]# cp /etc/issue ./
[root@localhost ~]# cat issue | tr 'a-z' 'A-Z' > /tmp/issue.out
[root@localhost ~]# cat /tmp/issue.out
CENTOS RELEASE 6.8 (FINAL)
KERNEL \R ON AN \M
TTY IS \L
HOSTNAME IS \N
TIME IS \T
2、將當前系統登錄用戶的信息轉換為大寫後保存至/tmp/who.out文件中
[root@localhost ~]# who | tr 'a-z' 'A-Z' > /tmp/who.out
[root@localhost ~]# cat /tmp/who.out
ROOT     TTY1         2008-08-09 19:54
ROOT     PTS/1        2008-08-10 01:07 (10.10.10.1)
3、一個linux用戶給root發郵件,要求郵件標題為”help”,郵件正文如下:

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

操作系統版本信息

[ping@localhost ~]$ echo "Hello, I am $(whoami) the system version is here, please help me to check it. $(cat /etc/redhat-release)" | mail -s "help" root
[ping@localhost ~]$ logout
You have new mail in /var/spool/mail/root
[root@localhost ~]# mail
>N  8 [email protected]  Sun Aug 10 06:46  18/690   "help"
& 8
Message  8:
From [email protected]  Sun Aug 10 06:46:24 2008
Return-Path: <[email protected]>
X-Original-To: root
Delivered-To: [email protected]
Date: Sun, 10 Aug 2008 06:46:24 +0800
To: [email protected]
Subject: help
User-Agent: Heirloom mailx 12.4 7/29/08
Content-Type: text/plain; charset=us-ascii
From: [email protected]
Status: R
Hello, I am ping the system version is here, please help me to check it. CentOS release 6.8 (Final)
4、將/root/下文件列表,顯示成一行,並文件名之間用空格隔開
[root@localhost ~]# ls /root | tr '\n' ' '
A anaconda-ks.cfg a.txt b c d install.log install.log.syslog issue manpages-zh-1.5.1.tar.gz test1 test10 test11
5、file1文件的內容為:”1 2 3 4 5 6 7 8 9 10” 計算出所有數字的總和

[root@localhost ~]# echo "1 2 3 4 5 6 7 8 9 10" | tr ' ' '+' | bc
55
6、刪除Windows文本文件中的'^M'字符
[root@localhost ~]# cat -A a.txt
aaaaaaaa^M$
bbbbbbbbbbbbbbb^M$
ccccccccccccccccccc^M$
vvvvvvvvvvvvvvvvvvvvvvvvv^M$
[root@localhost ~]# cat a.txt | tr -d '\r' >new.txt | cat new.txtaaaaaaaa
bbbbbbbbbbbbbbb
ccccccccccccccccccc
vvvvvvvvvvvvvvvvvvvvvvvvv
7、處理字符串“xt.,l 1 jr#!$mn2 c*/fe3 uz4”,只保留其中的數字和空格

[root@localhost ~]# echo "xt.,l 1 jr#ifconfigmn 2 c*/fe 3 uz 4" | tr -d '[[:alpha:]][[:punct:]]'
 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 file2
aaaa

bbbb

cccc

dddd
[root@localhost ~]# cat file2 | tr -s '\n' 
aaaa
bbbb
cccc
dddd
10、將文件中每個單詞(字母)顯示在獨立的一行,並無空行
[root@localhost ~]# cat file2
aaaa

bbbb

cccc

dddd
[root@localhost ~]# tr -cs '[:alpha:]' '\n' < file2
aaaa
bbbb
cccc
dddd

Copyright © Linux教程網 All Rights Reserved