【CentOS 7笔记32】,通配符、输入输出重定向#171116

hellopasswd


通配符

[root@localhost ~]# ls
	111  1.txt      222      2.txt  3.txt  abc      anaconda-ks.cfg  b.txt
	123  1.txt.tar  222.zip  333    9.txt  abc.txt  a.txt            text.txt.bz2
[root@localhost ~]# ls *txt	#以txt为后缀的所有字符的文件或目录
	1.txt  2.txt  3.txt  9.txt  abc.txt  a.txt  b.txt
[root@localhost ~]# ls *txt*	#以中间字符为txt的所有字符的文件或目录
1.txt  1.txt.tar  2.txt  3.txt  9.txt  abc.txt  a.txt  b.txt  text.txt.bz2
[root@localhost ~]# ls ?.txt	#以txt为后缀的一个或零个任意字符的文件或目录
1.txt  2.txt  3.txt  9.txt  a.txt  b.txt
[root[@localhost](https://my.oschina.net/u/570656) ~]# ls [13].txt
	1.txt  3.txt
[root[@localhost](https://my.oschina.net/u/570656) ~]# ls [29].txt
	2.txt  9.txt
[root[@localhost](https://my.oschina.net/u/570656) ~]# ls [0-9].txt	#指范围
	1.txt  2.txt  3.txt  9.txt
[root[@localhost](https://my.oschina.net/u/570656) ~]# ls [0-9a-z].txt
	1.txt  2.txt  3.txt  9.txt  a.txt  b.txt
[root[@localhost](https://my.oschina.net/u/570656) ~]# ls {2,9,b}.txt	#如同[29b].txt
	2.txt  9.txt  b.txt

输入输出重定向

正确输入重定向>

[root@localhost ~]# echo helloworld > 1.txt
[root@localhost ~]# cat 1.txt
	helloworld
[root@localhost ~]# echo helloworld > 1.txt
[root@localhost ~]# cat 1.txt
	helloworld

正确追加输入重定向>>

[root@localhost ~]# echo helloworld >> 1.txt
[root@localhost ~]# echo helloworld >> 1.txt
[root@localhost ~]# cat 1.txt
	helloworld
	helloworld
	helloworld

错误输入重定向2>

[root@localhost ~]# la / > 1.txt
	-bash: la: command not found
[root@localhost ~]# cat 1.txt
[root@localhost ~]# la / 2> 1.txt
[root@localhost ~]# cat 1.txt
	-bash: la: command not found

错误追加输入重定向2>>

[root@localhost ~]# la / 2>> 1.txt
[root@localhost ~]# la / 2>> 1.txt
[root@localhost ~]# cat 1.txt
	-bash: la: command not found
	-bash: la: command not found
	-bash: la: command not found

正确和错误输入重定向&>

[root@localhost ~]# ls
	111  1.txt      222      2.txt  3.txt  abc      anaconda-ks.cfg  b.txt
	123  1.txt.tar  222.zip  333    9.txt  abc.txt  a.txt            text.txt.bz2
[root@localhost ~]# ls 111.txt 111
	ls: cannot access 111.txt: No such file or directory
	111:
[root@localhost ~]# ls 111.txt 111 &> 1.txt
[root@localhost ~]# cat 1.txt
	ls: cannot access 111.txt: No such file or directory
	111:

正确和错误追加输入重定向&>>

[root@localhost ~]# ls 111.txt 111 &>> 1.txt
[root@localhost ~]# ls 111.txt 111 &>> 1.txt
[root@localhost ~]# cat 1.txt
	ls: cannot access 111.txt: No such file or directory
	111:
	ls: cannot access 111.txt: No such file or directory
	111:
	ls: cannot access 111.txt: No such file or directory
	111:

输出重定向

[root@localhost ~]# wc -l 1.txt
	6 1.txt
[root@localhost ~]# wc -l < 1.txt
	6
[root@localhost ~]# 2.txt < 1.txt	#左边必须为命令
	-bash: 2.txt: command not found

以此类推


修改于171116

转载于:https://my.oschina.net/hellopasswd/blog/1574237

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值