Linux 练习 - 标准IO和管道

1、将 /etc/issue 文件中的内容转换为大写后保存至 /tmp/issue.out 文件中
[yinxd@centos7 ~]$ cat /etc/issue
\S
Kernel \r on an \m

[yinxd@centos7 ~]$ cat /etc/issue | tr 'a-z' 'A-Z' > /tmp/issue.out

[yinxd@centos7 ~]$ cat /tmp/issue.out 
\S
KERNEL \R ON AN \M
2、将当前系统登录用户的信息转换为大写后保存至 /tmp/who.out 文件中
[yinxd@centos7 ~]$ who
yinxd    pts/0        2020-05-15 10:42 (10.10.10.1)
yinxd    pts/1        2020-05-15 10:38 (10.10.10.1)

[yinxd@centos7 ~]$ who | tr 'a-z' '[A-Z' > /tmp/who.out

[yinxd@centos7 ~]$ cat /tmp/who.out 
YINXD    PTS/0        2020-05-15 10:42 (10.10.10.1)
YINXD    PTS/1        2020-05-15 10:38 (10.10.10.1)
3、一个 linux 用户给 root 发邮件,要求邮件标题为 ”help” ,邮件正文如下:

Hello, I am 用户名,The system version is here,please help me to check it ,thanks!

操作系统版本信息

[yinxd@centos7 ~]$ echo -e  "Hello, I am `whoami`,The system version is here,please help me to check it ,thanks! \n `uname -r`" | mail -s "help" root

[root@centos7 ~]#
You have mail in /var/spool/mail/root

[root@centos7 ~]# cat /var/spool/mail/root

From yinxd@centos7.localdomain  Fri May 15 10:59:49 2020
Return-Path: <yinxd@centos7.localdomain>
X-Original-To: root
Delivered-To: root@centos7.localdomain
Received: by centos7.localdomain (Postfix, from userid 2006)
	id 52C73600419B; Fri, 15 May 2020 10:59:49 +0800 (CST)
Date: Fri, 15 May 2020 10:59:49 +0800
To: root@centos7.localdomain
Subject: help
User-Agent: Heirloom mailx 12.5 7/5/10
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Message-Id: <20200515025949.52C73600419B@centos7.localdomain>
From: yinxd@centos7.localdomain

Hello, I am yinxd,The system version is here,please help me to check it ,thanks! 
 3.10.0-1062.el7.x86_64
4、将 /root/ 下文件列表,显示成一行,并文件名之间用空格隔开
[yinxd@centos7 ~]$ sudo ls /root | tr '\n' ' '
5、计算 1+2+3+…+99+100 的总和
[yinxd@centos7 ~]$ echo {1..100} | tr ' ' '+' | bc
5050
6、删除 Windows 文本文件中的回车字符 ,即 “\r”
[yinxd@centos7 ~]$ file win.txt 
win.txt: ASCII text, with CRLF line terminators

[yinxd@centos7 ~]$ cat win.txt | tr -d '\r' > win2.txt

[yinxd@centos7 ~]$ file win2.txt 
win2.txt: ASCII text
7、处理字符串 “xt.,l 1 jr#!$mn 2 c*/fe 3 uz 4” ,只保留其中的数字和空格
[yinxd@centos7 ~]$ echo 'xt.,l 1 jr#bcmn 2 c*/fe 3 uz 4' | tr -d [:alpha:][:punct:]
 1  2  3  4
8、将 PATH 变量每个目录显示在独立的一行
[yinxd@centos7 ~]$ echo $PATH
/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/yinxd/.local/bin:/home/yinxd/bin

[yinxd@centos7 ~]$ echo $PATH | tr ':' '\n'
/usr/local/bin
/usr/bin
/usr/local/sbin
/usr/sbin
/home/yinxd/.local/bin
/home/yinxd/bin
9、将指定文件中 0-9 分别替代成 a-j
[yinxd@centos7 ~]$ ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.10.10.10  netmask 255.255.255.0  broadcast 10.10.10.255
        inet6 fe80::20c:29ff:fe81:4736  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:81:47:36  txqueuelen 1000  (Ethernet)
        RX packets 5854  bytes 1022811 (998.8 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 3940  bytes 528058 (515.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[yinxd@centos7 ~]$ ifconfig eth0 | tr '0-9' 'a-z' > /tmp/ifconfig.tmp

[yinxd@centos7 ~]$ cat /tmp/ifconfig.tmp
etha: flags=ebgd<UP,BROADCAST,RUNNING,MULTICAST>  mtu bfaa
        inet ba.ba.ba.ba  netmask cff.cff.cff.a  broadcast ba.ba.ba.cff
        inetg feia::cac:cjff:feib:ehdg  prefixlen ge  scopeid axca<link>
        ether aa:ac:cj:ib:eh:dg  txqueuelen baaa  (Ethernet)
        RX packets fjed  bytes bacjfeb (baaf.e KiB)
        RX errors a  dropped a  overruns a  frame a
        TX packets djij  bytes fdcjge (fca.e KiB)
        TX errors a  dropped a overruns a  carrier a  collisions a
10、将文件 /etc/centos-release 中每个单词(由字母组成)显示在独立一行,并无空行
[yinxd@centos7 ~]$ cat /etc/centos-release | tr -c [:alpha:] ' ' | tr -s ' ' '\n'
CentOS
Linux
release
Core
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值