管道符
命令1 | 命令2
命令1的输出结果作为命令2的操作对象
[root@localhost ~]# ls
access.log cangls.tar.bz2 install.log.syslog test3.log
anaconda-ks.cfg hello.sh lala.log test.log
cangls install.log test1.log
[root@localhost ~]# ls >> lalala.log
[root@localhost ~]# more lalala.log
access.log
anaconda-ks.cfg
cangls
cangls.tar.bz2
hello.sh
install.log
install.log.syslog
lalala.log
lala.log
test1.log
test3.log
test.log
[root@localhost ~]# ls | more
access.log
anaconda-ks.cfg
cangls
同理ps -ef|grep java 的意思就是:grep查询管道符前命令的输出结果。
与此相关的一个小技巧:netstat -an |grep ESTABLISHED | wc -l
上面这条命令是查询linux服务器当前链接的用户个数。
通配符
linux中可以识别的通配符就三个
? 匹配任意一个字符
* 匹配0个或多个任意字符,也就是所有内容
[] 匹配括号中任意一个字符。如[abc],匹配a,b,c任意一个字符,必须是一个
[-] 表示一个范围[a-z],[0-9]
[^] 逻辑非,表示匹配不是括号内的任意一个字符
一波操作练习:
[root@localhost dy]# aa=123
[root@localhost dy]# echo aa
aa
[root@localhost dy]# echo 'aa'
aa
[root@localhost dy]# echo "aa"
aa
[root@localhost dy]# echo $aa
123
[root@localhost dy]# echo '$aa'
$aa
[root@localhost dy]# echo "$aa"
123
[root@localhost dy]# aa='ls'
[root@localhost dy]# echo "$aa"
ls
[root@localhost dy]# aa=`ls`
[root@localhost dy]# echo "$aa"
dzl
huhuhu
ll22
lll
lll2
因为反引号不好区分,所以最好使用
[root@localhost dy]# aa=$(ls)
[root@localhost dy]# echo $aa
dzl huhuhu ll22 lll lll2