IO重定向 您所在的位置:网站首页 英语io是什么意思 IO重定向

IO重定向

2024-07-01 23:32| 来源: 网络整理| 查看: 265

特殊设备,空设备,也叫黑洞,数据进去都没了。

 

输出重定向(Output Redirection)的几种方法 1. 正常输出重定向:>(覆盖输出)、>>(追加输出)

例子:

2. 错误输出重定向:2>(覆盖输出)、2>>(追加输出) 1 2 3   ls /etc/issue1111 2>> /tmp/error.out catt /etc/issue 2>> /dev/null  正确和错误的都进行输出重定向: 新写法:COMMAND &> /path/to/somefile、COMMAND &>> /path/to/somefile 老写法:COMMAND > /path/to/somefile 2>&1、COMMAND >> /path/to/somefile 2>&1 1 2 3 4 ls /boot /err &> /tmp/all1.log # 新写法 ls /boot /err &>> /tmp/all2.log # 新写法 ls /boot /err > /tmp/all3.log 2>&1 # 老写法 ls /boot /err >> /tmp/all4.log 2>&1 # 老写法 输入重定向(Input Redirection)的方法 tr命令

tr [OPTION]... SET1 [SET2]把输入的数据当中的字符,凡是在SET1定义范围内出现的,通通对位转换为SET2出现的字符

tr SET1 SET2 < /path/from/somefile对位转化SET1中的字符为SET2中的字符 tr -d SET1 < /path/from/somefile删除指定集合里出现的字符 tr -s "\n" /path/from/somefile把指定的连续的字符以一个字符表示,压缩。 tr -cComplement ,取字符集的补集,通常与其他参数结合使用,例如-dc 1 2 3 4 5 6 7 8 9 10 11 12 [root❄centos7 ~]☭ tr 'a-z' 'A-Z' aabbcc33 AABBCC33 ^C [root❄centos7 ~]☭ tr 'a-z' 'A-Z' /app/issue2 [root❄centos7 ~]☭ cat /app/issue2 \S KERNEL \R ON AN \M

tips:如果是输入后再输出到同一个文件,就会清空这个文件,所以最好不要这么用,下面是一个错误示范:

1 2 3 4 5 [root❄centos7 ~]☭ cd /app/ [root❄centos7 app]☭ cp issue2 issue3 [root❄centos7 app]☭ tr 'a-z' 'A-Z' < issue3 >issue3 [root❄centos7 app]☭ cat issue3 [root❄centos7 app]☭

追加是可以的,在原有文件基础上再追加一段:

1 2 3 4 5 6 7 8 9 10 11 [root❄centos7 app]☭ cat issue2 \S KERNEL \R ON AN \M   [root❄centos7 app]☭ tr 'A-Z' 'a-z' < issue2 >> issue2 [root❄centos7 app]☭ cat issue2 \S KERNEL \R ON AN \M   \s kernel \r on an \m

dc结合使用

1 2 3 4 5 6 7 8 9 [root❄centos7 app]☭ echo {a..z} >f1 [root❄centos7 app]☭ cat f1 a b c d e f g h i j k l m n o p q r s t u v w x y z [root❄centos7 app]☭ tr -d 'f-n' hanjinze > songda > END   [root❄centos7 app]☭ cat /tmp/cat.out yulongjun zhaoweiqiang hanjinze songda -代表输出流

此段来源于:https://www.cnblogs.com/dachenzi/p/6790596.html

搭配cat

cat -:如果指定cat的文件为-,表示从标准输入读取(和直接使用cat,好像没什么区别)

搭配|

echo 123 | cat -:表示把管道符前面的输出流,在交给cat执行一遍(这就很牛逼了)

例子:

如果操作系统没有scp命令,只有ssh,那么是不是就不能远程拷贝了(前提:没有openssh-clients软件包)

利用-,就可以实现:

1 cat jdk.tar.gz | ssh 192.168.56.101 'cat - > /tmp/jdk.tar.gz'

cat jdk.tar.gz 产生输出流, 在管道后面的 - ,则可以接受输出流,并重定向到 /tmp/jdk.tar.gz



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有