【CentOS 7筆記32】,通配符、輸入輸出重定向#

shallow丿ovebash


通配符

[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

輸入輸出重定向

正確輸入重定向>.net

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

正確追加輸入重定向>>code

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

錯誤輸入重定向2>ip

[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>>file

[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

正確和錯誤輸入重定向&>command

[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:

輸出重定向di

[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

以此類推文件

相關文章
相關標籤/搜索