linux 打zip文件格式,Linux系统中文件打包及压缩格式与命令

本文详细介绍了在Linux环境下,如何使用tar命令结合gzip, bzip2, xz以及RAR工具进行文件打包、查看版本、压缩与解压缩,并展示了不同压缩工具的特点和参数。此外,还涵盖了如何设置压缩级别、测试压缩包完整性和删除原始文件的操作。
摘要由CSDN通过智能技术生成

Tar文件打包工具

查看当前系统下tar版本信息

[root@localhost ~]# tar --version

tar (GNU tar) 1.23

Copyright (C) 2010 Free Software Foundation, Inc.

License GPLv3+: GNU GPL version 3 or later .

This is free software: you are free to change and redistribute it.

There is NO WARRANTY, to the extent permitted by law.

Written by John Gilmore and Jay Fenlason.

[root@localhost ~]#

Tar命令示例

tar -cf archive.tar foo bar  # Create archive.tar from files foo and bar.

tar -tvf archive.tar         # List all files in archive.tar verbosely.

tar -xf archive.tar          # Extract all files from archive.tar.

文件操作参数

-c, --create               create a new archive

-t, --list                 list the contents of an archive

-f, --file=ARCHIVE         use archive file or device ARCHIVE

-x, --extract, --get       extract files from an archive

追加打包

-r, --append

增量打包               append files to the end of an archive

-u, --update               only append files newer than copy in archive

压缩选项

-j, --bzip2                filter the archive through bzip2

-z, --gzip, --gunzip, --ungzip   filter the archive through gzip

-v, --verbose              verbosely list files processed

-J, --xz                   filter the archive through xz

CentOS6.3最小化环境默认未包含xz压缩工具

[root@localhost ~]# yum install xz

[root@localhost ~]# tar -Jxvf zlib-1.2.8.tar.xz

Gzip压缩工具常用命令参数

-d, --decompress  decompress

-l, --list        list compressed file contents

-n, --no-name     do not save or restore the original name and time stamp

-N, --name        save or restore the original name and time stamp

-t, --test        test compressed file integrity

-v, --verbose     verbose mode

-1, --fast        compress faster

-9, --best        compress better

测试压缩包完整性

[root@localhost ~]# gzip -tv nginx-1.4.0.tar.gz

nginx-1.4.0.tar.gz:      OK

[root@localhost ~]#

查看压缩包文件列表

[root@localhost ~]# gzip -l nginx-1.4.0.tar.gz

compressed        uncompressed  ratio uncompressed_name

2847187            14213120  80.0% nginx-1.4.0.tar

[root@localhost ~]#

Bzip2压缩工具常用命令参数

-d --decompress     force decompression

-z --compress       force compression

-f --force          overwrite existing output files

-t --test           test compressed file integrity

-v --verbose        be verbose (a 2nd -v gives more)

-1 .. -9            set block size to 100k .. 900k

--fast              alias for -1

--best              alias for -9

[root@localhost ~]# bzip2 -d nginx-1.4.0.tar.bz2

[root@localhost ~]# bzip2 -tv nginx-1.4.0.tar.bz2

nginx-1.4.0.tar.bz2: ok

[root@localhost ~]#

XZ压缩工具完整命令参数

-z, --compress      force compression

-d, --decompress    force decompression

-t, --test          test compressed file integrity

-l, --list          list information about files

-k, --keep          keep (don't delete) input files

-f, --force         force overwrite of output file and (de)compress links

-c, --stdout        write to standard output and don't delete input files

-0 .. -9            compression preset; 0-2 fast compression, 3-5 good

compression, 6-9 excellent compression; default is 6

-e, --extreme       use more CPU time when encoding to increase compression

ratio without increasing memory usage of the decoder

-q, --quiet         suppress warnings; specify twice to suppress errors too

-v, --verbose       be verbose; specify twice for even more verbose

-h, --help          display this short help

-H, --long-help     display the long help (lists also the advanced options)

-V, --version       display the version number

Linux下RAR压缩格式的压缩及解压缩命令与参数

[root@localhost ~]# tar xzvf rarlinux-4.2.0.tar.gz

[root@localhost ~]# mv rar /usr/local/

[root@localhost ~]# export PATH=/usr/local/rar/:$PATH

常用命令参数

a             Add files to archive

c             Add archive comment

e             Extract files to current directory

t             Test archive files

x             Extract files with full path

-dw            Wipe files after archiving

-k             Lock archive

-m<0..5>       Set compression level (0-store...3-default...5-maximal)

-p[password]   Set password

压缩指定文件夹

[root@localhost ~]# rar a zlib.rar zlib-1.2.8

压缩指定文件或目录后进行完整性测试

[root@localhost ~]# rar a -t zlib.rar zlib-1.2.8

使用压缩级别参数提高压缩比率

[root@localhost ~]# ll zlib.rar

-rw-r--r-- 1 root root 692321 May  8 11:33 zlib.rar

[root@localhost ~]# rm -rf zlib.rar

[root@localhost ~]# rar a -m5 zlib.rar zlib-1.2.8

[root@localhost ~]# ll zlib.rar

-rw-r--r-- 1 root root 691643 May  8 11:34 zlib.rar

[root@localhost ~]#

生成压缩文件后删除原始文件

[root@localhost ~]# rar a -dw zlib.rar zlib-1.2.8

解压缩

[root@localhost ~]# rm -rf zlib-1.2.8

[root@localhost ~]# rar x zlib.rar

设置压缩包密码

[root@localhost ~]# rar a -p12345 zlib.rar zlib-1.2.8

解压缩含有密码的压缩包

[root@localhost ~]# rar x zlib.rar

RAR 4.20   Copyright (c) 1993-2012 Alexander Roshal   9 Jun 2012

Trial version             Type RAR -? for help

Extracting from zlib.rar

Enter password (will not be echoed) for Makefile.sas:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值