Linux:输入输出重定向

输入输出重定向

[space@space Desktop]$ touch heiha
[space@space Desktop]$ ls -l heiha 
-rw-rw-r--. 1 space space 0 Apr 17 16:57 heiha
[space@space Desktop]$ ll heiha > re.txt  #标准输出重定向 会覆盖文件中原有内容
[space@space Desktop]$ cat re.txt
-rw-rw-r--. 1 space space 0 Apr 17 16:57 heiha
[space@space Desktop]$ ll heiha >> re.txt    # >> 标准输出追加重定向 将输出内容追加到re.txt中
[space@space Desktop]$ cat re.txt 
-rw-rw-r--. 1 space space 0 Apr 17 16:57 heiha
-rw-rw-r--. 1 space space 47 Apr 17 16:59 heiha
-rw-rw-r--. 1 space space 47 Apr 17 16:59 heiha
[space@space Desktop]$ cat -n re.txt 
     1	-rw-rw-r--. 1 space space 0 Apr 17 16:57 heiha
     2	-rw-rw-r--. 1 space space 47 Apr 17 16:59 heiha
     3	-rw-rw-r--. 1 space space 47 Apr 17 16:59 heiha
[space@space Desktop]$ more re.txt 
-rw-rw-r--. 1 space space 0 Apr 17 16:57 heiha
-rw-rw-r--. 1 space space 47 Apr 17 16:59 heiha
-rw-rw-r--. 1 space space 47 Apr 17 16:59 heiha
[space@space Desktop]$ ll xxx
ls: cannot access xxx: No such file or directory
[space@space Desktop]$ ll xxx >>re.txt       #还是会显示在屏幕上 因为不是标准输出
ls: cannot access xxx: No such file or directory
[space@space Desktop]$ ll xxx 2>>re.txt  #错误输出追加重定向 不会覆盖文件中原有内容
[space@space Desktop]$ more re.txt 
-rw-rw-r--. 1 space space 0 Apr 17 16:57 heiha
-rw-rw-r--. 1 space space 47 Apr 17 16:59 heiha
-rw-rw-r--. 1 space space 47 Apr 17 16:59 heiha
ls: cannot access xxx: No such file or directory
[space@space Desktop]$ ll xxx 2>re.txt           #错误输出重定向 会覆盖文件中原有内容
[space@space Desktop]$ more re.txt 
ls: cannot access xxx: No such file or directory
2>  错误输出重定向
>   标准输出重定向
>>  标准输出追加重定向
2>> 错误输出追加重定向
<   标准输入重定向
[space@space Desktop]$ cat i.txt 
/etc
[space@space Desktop]$ wc -l < i.txt >re.txt # 文件作为命令的标准输入
[space@space Desktop]$ cat re.txt 
1
[space@space Desktop]$ ls < i.txt >re.txt   # 文件中的内容并不能作为命令的参数去执行    这里 < i.txt 不起作用
[space@space Desktop]$ cat re.txt 
a.txt
b.txt
heiha
i
i.txt
j
re.txt

转载于:https://my.oschina.net/spacewe/blog/884999

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值