2016年7月29日,星期五

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

[root@localhost /]# cat /etc/issue | tr 'a-z' 'A-Z' > /tmp/issue.out
[root@localhost /]# cat /tmp/issue.out 
\S
KERNEL \R ON AN \M
[root@localhost /]# cat /etc/issue
\S
Kernel \r on an \m

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

[root@localhost /]# echo $(who) | tr 'a-z' 'A-Z' > /tmp/who.out
[root@localhost /]# cat /tmp/who.out 
ROOT :0 2016-07-26 10:49 (:0) 
ROOT PTS/0 2016-07-26 11:01 (:0) 
ROOT PTS/1 2016-07-28 09:56 (10.1.250.28) 
ROOT TTY2 2016-07-27 15:03

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

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

操作系统版本信息

[qzx@localhost ~]$ echo -e "Hello, I am $(whoami),the system version is here,pleasehelp me to check it ,thanks"'!'"\n"`cat /etc/redhat-release` | mail -s "help" root
[qzx@localhost ~]$ exit
登出
[root@localhost ~]# mailHeirloom Mail version 12.5 7/5/10.  Type ? for help.
"/var/spool/mail/root": 1 message 1 new>N  1 qzx                   Thu Jul 28 20:10  18/717   "help"
& 1Message  1:
From qzx@localhost.localdomain  
Thu Jul 28 20:10:33 2016
Return-Path: <qzx@localhost.localdomain>X-Original-To: root
Delivered-To: root@localhost.localdomainDate: Thu, 28 Jul 2016 20:10:33 +0800
To: root@localhost.localdomainSubject: help
User-Agent: Heirloom mailx 12.5 7/5/10
Content-Type: text/plain; charset=us-ascii
From: qzx@localhost.localdomain (qzx)
Status: R
Hello, I am qzx,the system version is here,pleasehelp me to check it ,thanks!
CentOS Linux release 7.2.1511 (Core) 

&

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

[root@localhost ~]# ls -1 /root/ | tr '\n' ' '
acd anaconda-ks.cfg asd file1 help.test initial-setup-ks.cfg 公共 模板 视频 图片 文档 下载 音乐 桌面

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" > file1
[root@localhost ~]# cat file1 | tr ' ' '+' |bc55

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

        cat -A 20.txt |tr -d '^M' 

^M$
^M$
^M$
^M$
^M$
[qzx@localhost 桌面]$ cat -A 20.txt |tr -d '^M'
$
aewqf$
sad$
ad$
q$
$
sda$
$
asdq$

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

[root@localhost ~]# echo "xt.,l 1 jr#historymn2 c*/fe3 uz4"| tr -d '[:alpha:][:punct:]'
 1 2 3 4

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

[root@localhost ~]# echo $PATH | tr ':' '\n'
/usr/local/sbin
/usr/local/bin
/usr/sbin
/usr/bin
/root/bin

9、删除指定文件的空行

[root@localhost ~]# cat file1 | tr -s '\n'
adsfasf
a  fsf fsa
   afsa
asfsa  afasfa
qfwf

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

[root@localhost ~]# cat file1
 adsfasf
 a  fsf fsa
    afsa
asfsa  afasfa



qfwf




aaaaaaaaaaaaaa
aaaaaaaaaaaaaa
aaaaaaaaaaaaaa

sss

sss
sss

t:
f



[root@localhost ~]# cat file1 | tr -s ' [:punct:]' '\n'
adsfasf
a
fsf
fsa
afsa
asfsa
afasfa
qfwf
aaaaaaaaaaaaaa
aaaaaaaaaaaaaa
aaaaaaaaaaaaaa
sss
sss
sss
t
f