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 </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`,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,The systemversion is here,please help me to check it,thanks! 操作系统版本信息 [[email?protected] ~]# 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‘ (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |