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

  tr 'a-z' 'A-Z' < /etc/issue >/tmp/issue

  wKiom1ecb-agQ03_AAARDbaQmVI187.gif



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

   w(who) | tr 'a-z' 'A-Z' > /tmp/who.out

   wKiom1eccBWCJ0ySAAAm04cYM0c683.gif

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

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

操作系统版本信息

   echo -e  "hello ,I am `whoami`,the system version is here ,please help me    to check it ,thanks! \n`cat /etc/centos-release`" > /tmp/help

   mail -s help root < /tmp/help

  wKiom1eccICzcyA7AABXZrBQTvw695.gif


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

  ls -am /root | tr -t ',' ' '   m选项表示以逗号分隔

  wKiom1eccLzzIQSeAAAWacdMsPs588.gif


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

  echo "1 2 3 4 5 6  7  8     9    10"> tmp1 | cat /tmp/1 |tr -s ' '| tr -t ' ' '+'| bc

  wKioL1eccOazza7rAAAPEgdQnGI805.gif

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

  cat file | tr -d "\r" > file

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

  echo "xt.,l 1 jr#exitmn2 c*/fe3 uz4" | tr -d "[:alpha:][:punct:]"

   wKiom1eccS-xmArgAAALgx_z9zA190.gif

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

  echo $PATH | tr -t ":" "\n"

  wKiom1eccU_joJTXAAANqbfIGSE842.gif

9、删除指定文件的空行

  cat file | tr -s "\n"

  wKiom1eccXrT2Y_sAAAXPf3wf3E816.gif

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

  cat file | tr -s "[:space:] " | tr -t " " "\n" | tr -s "\n"

  wKioL1eccZ3D0orJAAAPY6Jux-8886.gif

  wKioL1eccbCjhKRMAAARHo_TiO8365.gif