1.将/etc/issue文件中的内容转换为大写后保存至/tmp/issue.out文件中
[root@localhost etc]# tr a-z A-Z </etc/issue >/tmp/issue
[root@localhost etc]# cat /tmp/issue
\S
KERNEL \R ON AN \M
2.将当前系统登录用户的信息转换为大写后保存至/tmp/who.out文件中
[root@localhost etc]# w
17:36:52 up 3 days, 22 min, 2 users, load average: 0.00, 0.01, 0.05
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root tty1 Mon17 3days 0.06s 0.06s -bash
root pts/0 10.0.0.110 Tue14 4.00s 1.43s 0.29s w
[root@localhost etc]# w|tr a-z A-Z >/tmp/who.out
[root@localhost etc]# cat /tmp/who.out
17:38:27 UP 3 DAYS, 24 MIN, 2 USERS, LOAD AVERAGE: 0.00, 0.01, 0.05
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
ROOT TTY1 MON17 3DAYS 0.06S 0.06S -BASH
ROOT PTS/0 10.0.0.110 TUE14 3.00S 1.15S 0.00S W
3.一个linux用户给root发邮件,要求邮件标题为”help” ,邮件正文如下:
Hello, I am 用户名,The system version is here,please help me to check it ,thanks!
操作系统版本信息
[root@localhost data]# su linux
[linux@localhost data]$ mail -s 'help' root@localhost << EOF
> Hello,I am $USER,The system version is here,please help me to check it,thanks!
> `uname -a`
> EOF
[linux@localhost data]$ exit
exit
[root@localhost data]# mail
Heirloom Mail version 12.5 7/5/10. Type ? for help.
"/var/spool/mail/root": 2 messages 2 new
>N 1 linux@localhost.loca Thu Aug 6 17:50 19/697 "help"
N 2 linux@localhost.loca Thu Aug 6 17:51 19/802 "help"
& 2
Message 2:
From linux@localhost.localdomain Thu Aug 6 17:51:06 2020
Return-Path: <linux@localhost.localdomain>
X-Original-To: root@localhost
Delivered-To: root@localhost.localdomain
Date: Thu, 06 Aug 2020 17:51:06 +0800
To: root@localhost.localdomain
Subject: help
User-Agent: Heirloom mailx 12.5 7/5/10
Content-Type: text/plain; charset=us-ascii
From: linux@localhost.localdomain
Status: R
Hello,I am linux,The system version is here,please help me to check it,thanks!
Linux localhost.localdomain 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
& exit
4.将/root/下文件列表,显示成一行,并文件名之间用空格隔开
[root@localhost ~]# ls -a|tr '\n' ' '
. .. acl.txt anaconda-ks.cfg .bash_history .bash_logout .bash_profile .bashrc .cshrc .lesshst .tcshrc .viminfo .vimrc
5.计算1+2+3+...+99+100的总和
[root@localhost ~]# echo {1..100}|tr ' ' +|bc
5050
6.删除Windows文本文件中的回车字符 ,即“\r”
[root@localhost data]# hexdump -C f4.txt
00000000 61 61 61 0d 0a 62 62 62 0d 0a 62 62 62 0d 0a 63 |aaa..bbb..bbb..c|
00000010 76 63 63 0d 0a 64 64 64 0d 0a 77 65 6c 63 6f 6d |vcc..ddd..welcom|
00000020 65 20 74 6f 20 68 69 6e 73 61 6e 67 |e to hinsang|
0000002c
[root@localhost data]# file f4.txt
f4.txt: ASCII text, with CRLF line terminators
[root@localhost data]# tr -d '\r' < f4.txt
aaa
bbb
bbb
cvcc
ddd
welcome to hinsang
7.处理字符串“xt.,l 1 jr#!$mn 2 c*/fe 3 uz 4”,只保留其中的数字和空格
[root@localhost data]# echo 'xt.,l 1 jr#!$mn 2 c*/fe 3 uz 4'|tr -dc '[[:digit:]][[:space:]]'
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.将指定文件中0-9分别替代成a-j
[root@localhost data]# seq 0 9 > f1.txt
[root@localhost data]# cat f1.txt
0
1
2
3
4
5
6
7
8
9
[root@localhost data]# cat f1.txt|tr '0-9' 'a-j'
a
b
c
d
e
f
g
h
i
j
10.将文件/etc/centos-release中每个单词(由字母组成)显示在独立一行,并无空行
[root@localhost ~]# cat /etc/centos-release|tr -d '\n'| tr ' ' '\n'
CentOS
Linux
release
7.6.1810
(Core)