标签:过程 名称 style grep create centos7 atd nbsp 压缩
命令语法: tar zcvf 生成压缩包路径/压缩包.tar.gz 压缩数据01,02,03....
巧记:
压缩名称为tar.gz,可以理解为tar命令,gz取压缩类型gizp的前2个辅音字母
参数说明:
z --- 数据压缩方式 gzip (--gzip, --gunzip, --ungzip filter the archive through gzip)
c --- 创建一个压缩文件(create create a new archive)
v --- 显示压缩过程(verbose verbosely list files processed)
f --- 指定压缩包路径信息
将链接文件进行压缩处理时:
tar zcvhf 生成压缩包路径/压缩包.tar.gz 需要进行压缩链接文件
h --- 指定压缩链接文件所指定源文件
注意压缩的参数建议加上-,因为很多命令的参数都加-
先创建压缩包,再把文件放到里面,解压缩时磁盘和CPU都会比较卡
注意不要压缩软链接,但是不知道文件是否为软链接,那么就可以加上参数h
[root@centos71 ~]# tar --help | grep "\-h"
-h, --dereference follow symlinks; archive and dump the files they
--hard-dereference follow hard links; archive and dump the files they
-?, --help give this help list
因为/只有一个,所以要去掉/
[root@centos71 ~]# tar -zcvf /tmp/etc.tar.gz /etc
[root@centos71 ~]# ll -h /tmp/etc.tar.gz
-rw-r--r-- 1 root root 9.8M Dec 13 21:19 /tmp/etc.tar.gz
[root@centos71 ~]# du -s /etc/
32096 /etc/
[root@centos71 ~]# du -sh /etc/
32M /etc/
[root@centos71 ~]# tar -xvf /tmp/etc.tar.gz [root@centos71 ~]# du -sh etc/ 32M etc/
[root@centos71 ~]# find -type f -name "m*.conf" | xargs tar zcvf /test/m.tar.gz
./etc/libreport/events.d/mailx_event.conf
./etc/libreport/plugins/mantisbt.conf
./etc/libreport/plugins/mantisbt_format.conf
./etc/libreport/plugins/mantisbt_format_analyzer_libreport.conf
./etc/libreport/plugins/mantisbt_formatdup.conf
./etc/libreport/plugins/mantisbt_formatdup_analyzer_libreport.conf
./etc/libreport/plugins/mailx.conf
./etc/ld.so.conf.d/mariadb-x86_64.conf
./etc/man_db.conf
./etc/mke2fs.conf
[root@centos71 ~]# ls /test
m.tar.gz
[root@centos71 ~]# tar -tf /test/m.tar.gz ./etc/libreport/events.d/mailx_event.conf ./etc/libreport/plugins/mantisbt.conf ./etc/libreport/plugins/mantisbt_format.conf ./etc/libreport/plugins/mantisbt_format_analyzer_libreport.conf ./etc/libreport/plugins/mantisbt_formatdup.conf ./etc/libreport/plugins/mantisbt_formatdup_analyzer_libreport.conf ./etc/libreport/plugins/mailx.conf ./etc/ld.so.conf.d/mariadb-x86_64.conf ./etc/man_db.conf ./etc/mke2fs.conf
[root@centos71 ~]# ls /test m.tar.gz [root@centos71 ~]# find -type f -name "m*.conf" -exec tar zcvf /test/m.conf.tar.gz {} \; ./etc/libreport/events.d/mailx_event.conf ./etc/libreport/plugins/mantisbt.conf ./etc/libreport/plugins/mantisbt_format.conf ./etc/libreport/plugins/mantisbt_format_analyzer_libreport.conf ./etc/libreport/plugins/mantisbt_formatdup.conf ./etc/libreport/plugins/mantisbt_formatdup_analyzer_libreport.conf ./etc/libreport/plugins/mailx.conf ./etc/ld.so.conf.d/mariadb-x86_64.conf ./etc/man_db.conf ./etc/mke2fs.conf [root@centos71 ~]# ls /test m.conf.tar.gz m.tar.gz
[root@centos71 ~]# tar -tf /test/m.conf.tar.gz ./etc/mke2fs.conf
[root@centos71 ~]# find -type f -name "m*.conf" -exec tar zcvf /test/m.conf.tar.gz {} +; ./etc/libreport/events.d/mailx_event.conf ./etc/libreport/plugins/mantisbt.conf ./etc/libreport/plugins/mantisbt_format.conf ./etc/libreport/plugins/mantisbt_format_analyzer_libreport.conf ./etc/libreport/plugins/mantisbt_formatdup.conf ./etc/libreport/plugins/mantisbt_formatdup_analyzer_libreport.conf ./etc/libreport/plugins/mailx.conf ./etc/ld.so.conf.d/mariadb-x86_64.conf ./etc/man_db.conf ./etc/mke2fs.conf [root@centos71 ~]# tar -tf /test/m.conf.tar.gz ./etc/libreport/events.d/mailx_event.conf ./etc/libreport/plugins/mantisbt.conf ./etc/libreport/plugins/mantisbt_format.conf ./etc/libreport/plugins/mantisbt_format_analyzer_libreport.conf ./etc/libreport/plugins/mantisbt_formatdup.conf ./etc/libreport/plugins/mantisbt_formatdup_analyzer_libreport.conf ./etc/libreport/plugins/mailx.conf ./etc/ld.so.conf.d/mariadb-x86_64.conf ./etc/man_db.conf ./etc/mke2fs.conf [root@centos71 ~]# ls /test m.conf.tar.gz m.tar.gz [root@centos71 ~]#
标签:过程 名称 style grep create centos7 atd nbsp 压缩
原文地址:https://www.cnblogs.com/wang618/p/12048441.html