shell脚本编程入门教程(4) 第二部分
2)搜索命令 grep 
支持正则过滤 
 
复制代码 代码示例:
[search@h1 ~]$ cat c.txt   
one  
two  
three  
four  
[search@h1 ~]$ grep t c.txt   
two  
three  
[search@h1 ~]$   
 
反向搜索参数-v,搜索除了搜索的东西,剩下的内容 
 
复制代码 代码示例:
[search@h1 ~]$ grep -v t c.txt   
one  
four  
[search@h1 ~]$  
显示行号-n,参数 
 
复制代码 代码示例:
[search@h1 ~]$ grep -v -n t c.txt   
1:one  
4:four  
[search@h1 ~]$  
只要计数,不要数据的使用-c参数 
 
复制代码 代码示例:
[search@h1 ~]$ grep -c t c.txt       
2  
[search@h1 ~]$
正则语法 
 
复制代码 代码示例:
[search@h1 ~]$ grep [tf] c.txt   
two  
three  
four  
[search@h1 ~]$ grep [tf] c.txt  
3)解压缩命令,通用用的最多的有unzip,tar -zxvf命令,前者用来解压zip压缩的文件,后者用来解压tar.gz结尾的压缩包,这两种类型,在JAVA开源的apache的官网下载的目录下,非常容易常见;(www.jb200.com 脚本学堂)
unzip  xxx.zip ,解压xxx.zip的内容 
tar -zxvf  xxx.tar.gz  解压xxx.tar.gz的压缩包
4) 
打包命令tar -zcvf /压缩包名.tar.gz /压缩的目录或文件 
打包命令zip -r /压缩包名.zip /压缩的目录或文件 
 
复制代码 代码示例:
[root@linux ~]# tar -cvf /tmp/etc.tar /etc <==仅打包,不压缩!  
[root@linux ~]# tar -zcvf /tmp/etc.tar.gz /etc <==打包后,以 
gzip 压缩  
[root@linux ~]# tar -jcvf /tmp/etc.tar.bz2 /etc <==打包后,以 bzip2 压缩 
有一个很大的压缩文件large.zip,我不想解压缩,只想看看它里面有什么: 
 
复制代码 代码示例:
# unzip -v large.zip 
有一个xxx.tar,我只想查看,不想解压 
 
复制代码 代码示例:
[search@h1 ~]$ tar -tf xx.tar