码迷,mamicode.com
首页 > 系统相关 > 详细

Linux IO和管道练习题

时间:2019-03-18 15:17:32      阅读:236      评论:0      收藏:0      [点我收藏+]

标签:cannot   指定   existing   alt   列表   $path   sys   字符   pat   

把/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 </etc/issue

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

cat >file.txt <out.txt

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

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

操作系统版本信息

mail -s "help" lsj <<EOF
> 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‘

Linux IO和管道练习题

标签:cannot   指定   existing   alt   列表   $path   sys   字符   pat   

原文地址:https://blog.51cto.com/9019400/2364695

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!