liunx常用命令3

1、grep  查找文件内容

grephellotest.txt   在某个文件中查找包含hello的内容,只要一行中有hello会把整行显示

grep -n hello test.txt   n显示查找到的内容的行号,

grep -i hello test.txt    不区分大小写

grep -v hello test.txt    除了hello所在的行不显示,即反向查找

grep -n hello . -r   查找整个目录中的所有文件,包含hello的内容   

grep常用正则表达式

grep -n ^h test.txt    这一行以h开头

grep -n o$ test.txt    这一行以o结尾

grep h. test.txt         这一行h后面只要有字符就会被搜索出来

2、find  查找文件

find /home -name 1.txt 目录下查找文件下名为1.txt的文件

find /home -name ‘*.txt’  在home目录下查找以txt结尾的文件  有通配符记得加引号

3、tar 归档管理

打包

tar cvf a.tar 2.txt 3.txt   f必须放在最后,f后面的第一个参数代表要生成的文件名,后面所有的参数是要打包的文件

列出包里的数据

tar tf a.tar

解包

tar xvf a.tar 如果没写目录,那包里的文件解开放到当前目录

tar xvf a.tar -C tar  解包到指定的文件夹,文件夹需要提前创建好  -C必须是大写的

4、gzip

生成压缩文件

1、打包   tar cf a.tar * 生成a.tar文件

2、压缩   gzip -r a.tar  生成a.tar.gz

生成解压文件

1、解压  gzip -d  a.tar.gz  生成a.tar文件

2、解包  tar xf a.tar ~/tar   解包到指定文件中

一步到位  打包并压缩

tar czf b.tar.gz  1.txt 2.txt  以gzip的方式打包并压缩

一步到位  解压并解包

tar xzf b.tar.gzip -C ~/home   以gzip的方式打包并且压缩

5、bzip2

一步到位  打包并压缩

tar cjf b.tar.bz2  1.txt 2.txt  以bzip2的方式打包并压缩

一步到位  解压并解包

tar xjf b.tar.bz2 -C ~/home   以bzip2的方式打包并且压缩

6、zip  unzip

zip -r zz *.txt  zz代表要生成的压缩文件,不需要写扩展名,会自动生成zip扩展名

unzip -d zz zz.zip  解压时会自动创建目录

压缩率  zip<gzip<bzip2

通用性zip>gzip>bzip2

liunx  中gzip用的较多

猜你喜欢

转载自blog.csdn.net/linzhongqingniao/article/details/86417815