linux管道生产大于消费,Linux IO和管道练习题

把/etc/fstab⽂件内容重定向到/tmp⽬录下⽂件名为fstab.out

cat /etc/fstab > /tmp/fstab.out

把hello world追加到/tmp/fstab.out⽂件尾部

echo "hello world" >>/tmp/fstab.out

禁⽌覆盖重定向和强制重定向

set -C

echo "hello magedu" >/tmp/fstab.out

-bash: /tmp/fstab.out: cannot overwrite existing file

设置禁⽌覆盖重定向后,可强制覆盖重定向

echo "hello magedu" >| /tmp/fstab.out

cat /tmp/fstab.out

hello magedu

把标准错误和标准输出分别重覆盖定向到不同的⽂件⾥,即标准错误重定向到falt.txt⽂件,标准输出重定向到correct.txt

which cat 2> falt.txt > correct.txt

cat correct.txt

/usr/bin/cat

cat falt.txt

wih cat 2> falt.txt > correct.txt

cat falt.txt

cat correct.txt

合并标准输出和标准错误覆盖重定向到out.txt⽂件⾥

which cat &> out.txt

cat out.txt

/usr/bin/cat

hich cat &>> out.txt

cat out.txt

/usr/bin/cat

bash: hich: command not found...

把所有⼩写字⺟转换为⼤写

tr a-z A-Z

把out.txt⽂件⾥的内容,写到file.txt⽂件⾥

cat >file.txt

使⽤mail命令root给lsj普通⽤户发邮件,要求邮件标题为”help”,邮件正⽂如下:

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

操作系统版本信息

mail -s "help" lsj <

> Hello, I am `who`,The system version is here,please help me to check it thanks!

> `cat /etc/redhat-release`

> EOF

将/etc/issue⽂件中的内容转换为⼤写后保存⾄/tmp/issue.out⽂件中

cat /etc/issue|tr 'a-z' 'A-Z' > /tmp/issue.out

将当前系统登录⽤户的信息转换为⼤写后保存⾄/tmp/who.out⽂件中

who |tr '[:lower:]' '[:upper:]' > /tmp/who.out

或者

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

⼀个linux⽤户给root发邮件,要求邮件标题为”help” ,邮件正⽂如下: Hello, I am ⽤户名,The systemversion is here,please help me to check it ,thanks! 操作系统版本信息

[root@magedu ~]# mail -s help root << EOF

>Hello, I am `whoami`.

>The system version is here,please help me to check it,thanks!

>`cat /etc/redhat-release`

>EOF

将/root/下⽂件列表,显⽰成⼀⾏,并⽂件名之间⽤空格隔开

ls /root |tr '\n' ' '

或:

ls -1 |tr '\n' ' '

计算1+2+3+..+99+100的总和

echo {1..100} | tr ' ' + | bc

删除Windows⽂本⽂件中的ʻ^Mʼ 字符

cat test.txt |tr -d '\r' > newtest.txt

处理字符串“xt.,l 1 jr#!$mn 2 c*/fe 3 uz 4”,只保留其中的数字和空格

echo "xt.,l 1 jr#!$mn 2 c*/fe 3 uz 4" | tr -dc '[:digit:]

[:space:]'

echo 'xt.,l 1 jr#!$mn2 c*/fe3 uz4' |tr -d '[:punct:]' |tr -d 'a-z'

将PATH变量每个⽬录显⽰在独⽴的⼀⾏

echo $PATH |tr ':' '\n'

将指定⽂件中0-9分别替代成a-j

echo {0..9}|tr '0-9' 'a-j'

将⽂件/etc/centos-release中每个单词(由字⺟组成)显⽰在独⽴⼀⾏,并⽆空⾏

cat /etc/centos-release |tr -cs '[:alpha:]' '\n'

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值