1 tar

.tar 只是进行打包,并没有压缩。 则:
用tar-cvf进行打包
用tar-xvf进行解包。 .tar.gz 是既打包又压缩 ,则:
tar –czvf [压缩包名] [文件或目录] // 打包,且使用 gzip 压缩
注: 生成的【压缩包的包名】可随意命名,tar命令做解压、压缩时 均不会受影响。
但建议,尽量规范化: 使用了 tar 打包,则:包名的文件格式后缀 第1段子后缀命名为 file.tar ; 以此类推,使用了 gizp 做压缩,则: .gz;若 二者均有使用,则: file.tar.gz
tar –xzvf [压缩包名] // 解包,且该包为 gzip 的压缩包
注: -z,--gzip, --gunzip, --ungzip : 通过 gzip 过滤归档。如果被解压的包并没有通过gz压缩,则 使用了-z参数会报错(gzip: stdin: not in gzip format) .gz 只压缩。只能针对文件。如果需要对一个目录下的全部文件压缩,则:
gzip -r [目录] // 文件夹压缩
gzip [文件名] // 文件压缩
gzip –d [文件名] // 文件解压
  • tar 命令参数详解
shell# man tar
NAME
tar - manual page for tar 1.26 SYNOPSIS
tar [OPTION...] [FILE]... DESCRIPTION
GNU `tar' saves many files together into a single tape or disk archive, and can restore individual files from the archive. Note that this manual page contains just very brief description (or more like a list of possible functionality) originally generated by the
help2man utility. The full documentation for tar is maintained as a Texinfo manual. If the info and tar programs are properly installed at
your site, the command `info tar' should give you access to the complete manual. EXAMPLES
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. DEFAULTS
*This* tar installation defaults to: --format=gnu -f- -b20 --quoting-style=escape --rmt-command=/sbin/rmt --rsh-command=/usr/bin/rsh Main operation mode:
-A, --catenate, --concatenate
append tar files to an archive -c, --create
create a new archive -d, --diff, --compare
find differences between archive and file system --delete
delete from the archive (not on mag tapes!) -r, --append
append files to the end of an archive -t, --list
list the contents of an archive --test-label
test the archive volume label and exit -u, --update
only append files newer than copy in archive -x, --extract, --get
extract files from an archive Common options:
-C, --directory=DIR
change to directory DIR -f, --file=ARCHIVE
use archive file or device ARCHIVE -j, --bzip2
filter the archive through bzip2 -J, --xz
filter the archive through xz -p, --preserve-permissions
extract information about file permissions (default for superuser) -v, --verbose
verbosely list files processed -z, --gzip
filter the archive through gzip Operation modifiers:
--check-device
check device numbers when creating incremental archives (default) -g, --listed-incremental=FILE
handle new GNU-format incremental backup -G, --incremental
handle old GNU-format incremental backup --ignore-failed-read
do not exit with nonzero on unreadable files --level=NUMBER
dump level for created listed-incremental archive -n, --seek
archive is seekable --no-check-device
do not check device numbers when creating incremental archives --no-seek
archive is not seekable --occurrence[=NUMBER]
process only the NUMBERth occurrence of each file in the archive; this option is valid only in conjunction with one of the subcommands
--delete, --diff, --extract or --list and when a list of files is given either on the command line or via the -T option; NUMBER
defaults to 1 --sparse-version=MAJOR[.MINOR]
set version of the sparse format to use (implies --sparse) -S, --sparse
handle sparse files efficiently Overwrite control:
-k, --keep-old-files
don't replace existing files when extracting, treat them as errors --keep-newer-files
don't replace existing files that are newer than their archive copies --no-overwrite-dir
preserve metadata of existing directories --overwrite
overwrite existing files when extracting --overwrite-dir
overwrite metadata of existing directories when extracting (default) --recursive-unlink
empty hierarchies prior to extracting directory --remove-files
remove files after adding them to the archive --skip-old-files
don't replace existing files when extracting, silently skip over them -U, --unlink-first
remove each file prior to extracting over it -W, --verify
attempt to verify the archive after writing it Select output stream:
--ignore-command-error ignore exit codes of children --no-ignore-command-error
treat non-zero exit codes of children as error -O, --to-stdout
extract files to standard output --to-command=COMMAND
pipe extracted files to another program Handling of file attributes:
--atime-preserve[=METHOD]
preserve access times on dumped files, either by restoring the times after reading (METHOD='replace'; default) or by not setting the
times in the first place (METHOD='system') --delay-directory-restore
delay setting modification times and permissions of extracted directories until the end of extraction --group=NAME
force NAME as group for added files --mode=CHANGES
force (symbolic) mode CHANGES for added files --mtime=DATE-OR-FILE
set mtime for added files from DATE-OR-FILE -m, --touch
don't extract file modified time --no-delay-directory-restore
cancel the effect of --delay-directory-restore option --no-same-owner
extract files as yourself (default for ordinary users) --no-same-permissions
apply the user's umask when extracting permissions from the archive (default for ordinary users) --numeric-owner
always use numbers for user/group names --owner=NAME
force NAME as owner for added files -p, --preserve-permissions, --same-permissions
extract information about file permissions (default for superuser) --preserve
same as both -p and -s --same-owner
try extracting files with the same ownership as exists in the archive (default for superuser) -s, --preserve-order, --same-order
sort names to extract to match archive Handling of extended file attributes:
--acls Enable the POSIX ACLs support --no-acls
Disable the POSIX ACLs support --no-selinux
Disable the SELinux context support --no-xattrs
Disable extended attributes support --selinux
Enable the SELinux context support --xattrs
Enable extended attributes support --xattrs-exclude=MASK
specify the exclude pattern for xattr keys --xattrs-include=MASK
specify the include pattern for xattr keys Device selection and switching:
-f, --file=ARCHIVE
use archive file or device ARCHIVE --force-local
archive file is local even if it has a colon -F, --info-script=NAME, --new-volume-script=NAME
run script at end of each tape (implies -M) -L, --tape-length=NUMBER
change tape after writing NUMBER x 1024 bytes -M, --multi-volume
create/list/extract multi-volume archive --rmt-command=COMMAND
use given rmt COMMAND instead of rmt
--rsh-command=COMMAND
use remote COMMAND instead of rsh --volno-file=FILE
use/update the volume number in FILE Device blocking:
-b, --blocking-factor=BLOCKS
BLOCKS x 512 bytes per record -B, --read-full-records
reblock as we read (for 4.2BSD pipes) -i, --ignore-zeros
ignore zeroed blocks in archive (means EOF) --record-size=NUMBER
NUMBER of bytes per record, multiple of 512 Archive format selection:
-H, --format=FORMAT
create archive of the given format FORMAT is one of the following: gnu GNU tar 1.13.x format oldgnu GNU format as per tar <= 1.12 pax POSIX 1003.1-2001 (pax) format posix same as pax ustar POSIX 1003.1-1988 (ustar) format v7 old V7 tar format --old-archive, --portability
same as --format=v7 --pax-option=keyword[[:]=value][,keyword[[:]=value]]...
control pax keywords --posix
same as --format=posix -V, --label=TEXT
create archive with volume name TEXT; at list/extract time, use TEXT as a globbing pattern for volume name Compression options:
-a, --auto-compress
use archive suffix to determine the compression program -I, --use-compress-program=PROG
filter through PROG (must accept -d) -j, --bzip2
filter the archive through bzip2 -J, --xz
filter the archive through xz --lzip filter the archive through lzip --lzma filter the archive through lzma --lzop --no-auto-compress
do not use archive suffix to determine the compression program -z, --gzip, --gunzip, --ungzip
filter the archive through gzip -Z, --compress, --uncompress
filter the archive through compress Note: You might need to install external program (lzip/ncompress/lzma...) to use some of these compression options Local file selection:
--add-file=FILE
add given FILE to the archive (useful if its name starts with a dash) --backup[=CONTROL]
backup before removal, choose version CONTROL -C, --directory=DIR
change to directory DIR --exclude=PATTERN
exclude files, given as a PATTERN --exclude-backups
exclude backup and lock files --exclude-caches
exclude contents of directories containing CACHEDIR.TAG, except for the tag file itself --exclude-caches-all
exclude directories containing CACHEDIR.TAG --exclude-caches-under exclude everything under directories containing
CACHEDIR.TAG --exclude-tag=FILE
exclude contents of directories containing FILE, except for FILE itself --exclude-tag-all=FILE exclude directories containing FILE --exclude-tag-under=FILE
exclude everything under directories containing FILE --exclude-vcs
exclude version control system directories -h, --dereference
follow symlinks; archive and dump the files they point to --hard-dereference
follow hard links; archive and dump the files they refer to -K, --starting-file=MEMBER-NAME
begin at member MEMBER-NAME in the archive --newer-mtime=DATE
compare date and time when data changed only --no-null
disable the effect of the previous --null option --no-recursion
avoid descending automatically in directories --no-unquote
do not unquote filenames read with -T --null -T reads null-terminated names, disable -C -N, --newer=DATE-OR-FILE, --after-date=DATE-OR-FILE
only store files newer than DATE-OR-FILE --one-file-system
stay in local file system when creating archive -P, --absolute-names
don't strip leading `/'s from file names --recursion
recurse into directories (default) --suffix=STRING
backup before removal, override usual suffix ('~' unless overridden by environment variable SIMPLE_BACKUP_SUFFIX) -T, --files-from=FILE
get names to extract or create from FILE --unquote
unquote filenames read with -T (default) -X, --exclude-from=FILE
exclude patterns listed in FILE
  • 解压: 解压压缩文件到指定目录
tar -xvf <dirName/compressedFile>.tar.gz -C <targetDir> # 解出 compressedFile.tar.gz 包中所有文件
-x, --extract, --get 解压,从归档中【解出】文件
-c, --create create a new archive 压缩,创建一个压缩文件
-C, --directory=DIR change to directory DIR 改变至目录 DIR
-v, --verbose 详细地列出处理的文件
-f, --file=ARCHIVE 使用归档文件或 ARCHIVE 设备
-z, --gzip, --gunzip, --ungzip 通过 gzip 过滤归档
-j, --bzip2 filter the archive through bzip2 通过 bzip2 过滤压缩文件 tar -xvf <dirName/compressedFile>.tar -C <targetDir> # 解出 compressedFile.tar 包中所有文件 tar -xjf <dirName/compressedFile>.tar.bz2 -C <targetDir> # 解压 compressedFile.tar.bz2 的文件
  • 压缩

    (↓方式1↓ 推荐)
tar -czvf fileName.tar.gz dirName
# 对 dirName 文件(夹) 【打包(-c)】,且【压缩(-z)】 为 文件名称为 fileName.tar.gz 的压缩包
-c, --create create a new archive 压缩,创建一个压缩文件
-v, --verbose 详细地列出处理的文件
-f, --file=ARCHIVE 使用归档文件或 ARCHIVE 设备
-z, --gzip, --gunzip, --ungzip 通过 gzip 过滤归档

(↓方式2↓)

tar -cvf fileName.tar.gz dirName
# 对 dirName 文件(夹) 【打包(-c)】,且【压缩(-z)】 为 文件名称为 fileName.tar.gz 的压缩包
-c, --create create a new archive 压缩,创建一个压缩文件
-v, --verbose 详细地列出处理的文件
-f, --file=ARCHIVE 使用归档文件或 ARCHIVE 设备

2 zip / unzip

  • 解压
unzip <dirName/compressedFile>.zip -d <targetDir>

unzip -o /opt/sdc/ue/tomcat/portal.zip -d /opt/sdc/ue/tomcat/webapps

unzip -O CP936 xxx.zip 或者 zip -O CP936 -o xxx.zip
CP936 -- GBK: IBM在发明Code Page的时候将GBK编码集放在第936页,所以叫CP936
UTF8 -- UTF-8(8-bit Unicode Transformation Format)/ 一种针对Unicode的可变长度字符编码
  • 压缩
zip -v filename.zip a.c b.c c.c e.c   # 压缩文件

zip -r <dirName/compressedFile>.zip <targetDir> # 压缩指定目录的文件

zip -r filename.zip file1 file2 file3 <targetDir>     # 压缩多个文件或目录

3 gzip / gunzip

GNU zip

gunzip是gzip的硬链接,请参考gzip

  • 解压
gunzip -c abc.sql.gz > abc.sql # 解压到指定目录,保留源文件,-c

gzip -dv 压缩文件	# 解压并打印执行过程
  • 压缩
gzip -c 待压缩文件 > 带压缩文件.gz	# 压缩文件并保留源文件

X 参考文献

[Linux]常用命令之【tar/zip/unzip/gzip/gunzip】的更多相关文章

  1. linux常用命令:tar 命令

    通过SSH访问服务器,难免会要用到压缩,解压缩,打包,解包等,这时候tar命令就是是必不可少的一个功能强大的工具.linux中最流行的tar是麻雀虽小,五脏俱全,功能强大. tar 命令可以为linu ...

  2. linux常用命令(21)tar命令

    通过SSH访问服务器,难免会要用到压缩,解压缩,打包,解包等,这时候tar命令就是是必不可少的一个功能强大的工具.linux中最流行的tar是麻雀虽小,五脏俱全,功能强大. tar命令可以为linux ...

  3. Linux 常用命令九 tar

    一.tar命令 tar命令用于打包,解包. gzip命令用于压缩,解压缩. bzip2命令用于压缩,解压缩. 这三个是在linux中常用的,还有一些不常用的. tar打包: wang@wang:~/w ...

  4. 2017-07-07(zip unzip gzip gunzip)

    zip压缩格式 zip zip 压缩文件名   源文件    (压缩文件) zip -r    压缩文件名   源文件   (压缩目录) unzip unzip 压缩名 .gz压缩格式 gzip gz ...

  5. linux常用命令加实例大全

    目  录引言    1一.安装和登录    2(一)    login    2(二)    shutdown    2(三)    halt    3(四)    reboot    3(五)    ...

  6. 2020非常全的软件测试linux常用命令全集,linux面试题及参考答案

    一.前言: 作为一名软件测试工程师,我相信大部分的人都和Linux打过交道,因为我们的服务器一般都是装的Linux操作系统,包括各种云服务器也都是用的Linux,目前主流是CentOS7,那么对于一个 ...

  7. linux常用命令与实例小全

    转至:https://www.cnblogs.com/xieguohui/p/8296864.html  linux常用命令与实例小全 阅读目录(Content) 引言 一.安装和登录 (一)    ...

  8. Linux常用命令(三)

    1.top 说明:即时显示 process 的动态 语法格式:top [-] [d delay] [q] [c] [S] [s] [i] [n] [b]基本参数:d : 改变显示的更新速度,或是在交谈 ...

  9. linux常用命令详解

    Linux提供了大量的命令,利用它可以有效地完成大量的工作,如磁盘操作.文件存取.目录操作.进程管理.文件权限设定等.所以,在Linux系统上工作离不开使用系统提供的命令.要想真正理解Linux系统, ...

  10. linux常用命令详解 (一) 安装和登录命令

    Linux必学的60个命令   Linux提供了大量的命令,利用它可以有效地完成大量的工 作,如磁盘操作.文件存   Linux提供了大量的命令,利用它可以有效地完成大量的工作,如磁盘操作.文件存取. ...

随机推荐

  1. openlayers-1 下载及安装使用

    javascript - Import from in Openlayers - Geographic Information Systems Stack Exchange 在浏览器中运行开放层示例 ...

  2. Deformable DETR (ICLR2021)

    Pre-Trained Image Processing Transformer paper:https://arxiv.org/abs/2010.04159 code:https://github. ...

  3. C# POST multipart/form-data 方式提交数据

    一.提交方法 /// <summary> /// MultipartFormData Post方式提交 /// </summary> /// <param name=&q ...

  4. intellij idea中怎么没有git版本控制设置项

    在使用intellij idea的时候想要使用git进行版本控制,但是在设置项和界面没有发现相关内容,怎么回事呢? 我们先打开电脑,从桌面的快捷方式打开intellij idea,进入到intelli ...

  5. Mac Idea2018.1.6版 利用脚本激活安装详解

    下载安装包:链接: https://pan.baidu.com/s/1W4alLXUeQ6xazkNEtB8I9w 提取码: w6rg 下载脚本:链接: https://pan.baidu.com/s ...

  6. 《JavaScript高级程序设计》Chapter04 变量,作用域,内存

    原始值&引用值 原始值(primitive value):Undefined, Null, Boolean, Number, String, Symbol 按值访问,直接操作存储在变量中的实际 ...

  7. MP逻辑删除

    在实体类中加上@TableLogic注解 在配置类中加入逻辑删除插件

  8. JS this指向相关

    function Foo() { getName = function() { console.log(1) } return this;}Foo.getName = function() { con ...

  9. CentOS7 进入修复模式的办法

    有时候配置Centos文件修改错误会导致系统无法登录,可以通过修复模式进行单用户运行模式,进行修复. 具体操作如下: 1.重启服务器,在选择内核界面使用上下箭头移动 2.选择内核并按"e&q ...

  10. 【Leetcode】 剑指offer:栈与队列 --Day01

    写在前面 2023届秋招形势严峻,作为2024届本科生倍感压力.时间紧迫,需要加快脚步. 计划之一是在未来的36天时间里通关Leetcode的剑指offer系列算法题.这一系列的学习周期为31天,也就 ...