解压缩命令tar zip rar

╰+哭是因爲堅強的太久メ 2022-02-20 10:19 408阅读 0赞

文章目录

  • 打包和压缩的概念
  • tar
    • 常用独立命令
    • 打包压缩
    • 查阅tar包内有哪些文件
    • 解压缩到指定目录(默认是当前目录)
    • 只将tar内的部分文件解压出来
    • 其他命令(其他)
  • zip和unzip
  • rar和unrar

打包和压缩的概念

tar命令可以为linux的文件和目录创建档案
利用tar,可以为某一特定文件创建档案(备份文件),也可以在档案中改变文件,或者向档案中加入新的文件
tar最初被用来在磁带上创建档案,现在,用户可以在任何设备上创建档案。
利用tar命令,可以把一大堆的文件和目录全部打包成一个文件,这对于备份文件或将几个文件组合成为一个文件以便于网络传输是非常有用的。

首先要弄清两个概念:打包和压缩。 打包是指将一大堆文件或目录变成一个总的文件; 压缩则是将一个大的文件通过一些压缩算法变成一个小文件。
为什么要区分这两个概念呢?
这源于Linux中很多压缩程序只能针对一个文件进行压缩,这样当你想要压缩一大堆文件时,你得先将这一大堆文件先打成一个包(tar命令),然后再用压缩程序进行压缩(gzip
bzip2命令)。

tar

  1. SYNOPSIS
  2. tar [-] A --catenate --concatenate | c --create | d --diff --compare | --delete | r --append | t --list | --test-label | u --update | x --extract --get [options] [pathname ...]
  3. DESCRIPTION
  4. Tar stores and extracts files from a tape or disk archive.
  5. Tar从磁带或磁盘存档文件中存储和提取文件。

常用独立命令

  1. FUNCTION LETTERS
  2. Main operation mode:
  3. -A, --catenate, --concatenate
  4. append tar files to an archive
  5. 将文件附加到存档文件中
  6. -c, --create
  7. create a new archive
  8. 创建一个新的存档
  9. -d, --diff, --compare
  10. find differences between archive and file system
  11. 查找归档和文件系统之间的差异
  12. --delete
  13. delete from the archive (not on mag tapes!)
  14. 从存档中删除(不要在mag磁带上删除!)
  15. -r, --append
  16. append files to the end of an archive
  17. 将文件附加到归档文件的末尾
  18. -t, --list
  19. list the contents of an archive
  20. 列出归档文件的内容
  21. --test-label
  22. test the archive volume label and exit
  23. -u, --update
  24. only append files newer than copy in archive
  25. 只添加比存档中的副本更新的文件(—更新
  26. -x, --extract, --get
  27. extract files from an archive
  28. 从归档文件中提取文件

重要:上面的命令是独立的命令,压缩解压都要用到其中一个,可以和别的命令连用但只能用其中一个。
下面的参数是根据需要在压缩或解压档案时可选的。(其中-f命令是必选的)

打包压缩

  1. tar -cvf log.tar log2012.log 仅打包,不压缩!
  2. tar -zcvf log.tar.gz log2012.log 打包后,以 gzip 压缩
  3. tar -jcvf log.tar.bz2 log2012.log 打包后,以 bzip2 压缩
  4. 在选项f之后的文件档名是自己取的,我们习惯上都用 .tar 来作为辨识。
  5. 如果加z选项,则以.tar.gz或.tgz来代表gzip压缩过的tar包;
  6. 如果加j选项,则以.tar.bz2来作为tar包名。
  7. -j, --bzip2
  8. -z, --gzip, --gunzip --ungzip
  9. -v, --verbose
  10. verbosely list files processed
  11. 详细列出处理过的文件
  12. -f, --file ARCHIVE
  13. use archive file or device ARCHIVE
  14. 使用存档文件或设备存档(指定存档文件)
  15. 切记,这个参数是最后一个参数,后面只能接档案名。
  16. tar 命令 必须和-f命令连用
  17. 在选项f之后的文件档名是自己取的,我们习惯上都用 .tar 来作为辨识。 如果加z选项,则以.tar.gz或.tgz来代表gzip压缩过的tar包;如果加j选项,则以.tar.bz2来作为tar包名。

查阅tar包内有哪些文件

  1. tar -ztvf log.tar.gz
  2. 由于我们使用 gzip 压缩的log.tar.gz,所以要查阅log.tar.gz包内的文件时,就得要加上z这个选项了。t的意思是查看文档内容

在这里插入图片描述

解压缩到指定目录(默认是当前目录)

  1. tar -xvf archive.tar -C /tmp 将压缩包释放到 /tmp目录下
  2. jz选项依据压缩属性需要加上
  3. -C, --directory DIR
  4. change to directory DIR

只将tar内的部分文件解压出来

在这里插入图片描述

其他命令(其他)

  1. -[0-7][lmh]
  2. specify drive and density
  3. 指定驱动器和密度
  4. -a, --auto-compress
  5. use archive suffix to determine the compression program
  6. 使用archive后缀确定压缩程序
  7. --backup
  8. backup before removal, choose version CONTROL
  9. --exclude=PATTERN
  10. exclude files, given as a PATTERN
  11. --exclude-ignore=FILE
  12. read exclude patterns for each directory from FILE, if it exists
  13. 从文件中排除每个目录的模式(如果存在的话)
  14. --exclude-ignore-recursive=FILE
  15. read exclude patterns for each directory and its subdirectories from FILE, if it exists
  16. read从文件中排除每个目录及其子目录的模式(如果存在的话)
  17. --exclude-tag=FILE
  18. exclude contents of directories containing FILE, except for FILE itself
  19. 排除包含文件的目录的内容,文件本身除外
  20. --exclude-tag-all=FILE
  21. exclude directories containing FILE
  22. 排除包含文件的目录
  23. --exclude-tag-under=FILE
  24. exclude everything under directories containing FILE
  25. 排除包含文件的目录下的所有内容
  26. -k, --keep-old-files
  27. don't replace existing files when extracting, treat them as errors
  28. 解压时不要替换现有文件,将它们视为错误
  29. -m, --touch
  30. don't extract file modified time
  31. 不要提取文件修改时间
  32. -N, --newer, --after-date DATE-OR-FILE
  33. only store files newer than DATE-OR-FILE
  34. 只存储比DATE-OR-FILE更新的文件
  35. -O, --to-stdout
  36. extract files to standard output
  37. 将文件解压缩到标准输出
  38. -p, --preserve-permissions, --same-permissions 保留权限,相同权限
  39. extract information about file permissions (default for superuser)
  40. 提取有关文件权限的信息(超级用户默认)
  41. --recursion
  42. recurse into directories (default)
  43. 递归到目录(默认)
  44. -U, --unlink-first
  45. remove each file prior to extracting over it
  46. 在提取每个文件之前删除它
  47. --unquote
  48. unquote input file or member names (default)
  49. 不用引号 对输入文件或成员名称(默认)
  50. --utc
  51. print file modification times in UTC
  52. UTC打印文件修改时间
  53. -w, --interactive, --confirmation
  54. ask for confirmation for every action
  55. 对每一个动作都要确认
  56. -W, --verify
  57. attempt to verify the archive after writing it
  58. 尝试在编写存档之后验证它
  59. -Z, --compress, --uncompress
  60. ——压缩、解压缩
  61. EXAMPLES
  62. Create archive.tar from files foo and bar.
  63. tar -cf archive.tar foo bar
  64. List all files in archive.tar verbosely.
  65. tar -tvf archive.tar
  66. Extract all files from archive.tar.
  67. tar -xf archive.tar

zip和unzip

zip命令可以用来解压缩文件,或者对文件进行打包操作。zip是个使用广泛的压缩程序,文件经它压缩后会另外产生具有“.zip”扩展名的压缩文件。

安装
在这里插入图片描述

  1. zip all.zip *.jpg 这条命令是将所有.jpg的文件压缩成一个zip
  2. unzip all.zip 这条命令是将all.zip中的所有文件解压出来
  3. zip -r file1.zip file1 file2 dir1 将几个文件和目录同时压缩成一个zip格式的压缩包
  4. -r:递归处理,将指定目录下的所有文件和子目录一并处理;
  5. -v:显示指令执行过程或显示版本信息;

rar和unrar

  1. 安装: sudo apt-get install rar unrar
  2. 或者可从http://www.rarsoft.com/download.htm下载 RAR for Linux 编译安装
  3. # tar -xzpvf rarlinux-3.8.0.tar.gz
  4. # cd rar
  5. # make
  6. 这样就安装好了,安装之后就有了rarunrar这两个程序,rar是压缩程序,unrar是解压程序。它们的参数选项很多,可用命令rar -helpunrar -help查看,这里亦简单举例说明一下其用法:
  7. a Add files to archive
  8. e Extract files without archived paths
  9. # rar a test.rar test.jpg test.png
  10. 这条命令是将test.jpgtest.png压缩成一个rar
  11. # rar a test.rar *.jpg
  12. 这条命令是将所有.jpg的文件压缩成一个rar
  13. # rar a test.rar test
  14. 这条命令是将文件夹test压缩成一个rar
  15. # unrar e test.rar
  16. 这条命令是将test.rar中的所有文件解压出来
  17. 也可以用 rar e test.rar

在这里插入图片描述
在这里插入图片描述

发表评论

表情:
评论列表 (有 0 条评论,408人围观)

还没有评论,来说两句吧...

相关阅读

    相关 打包 压缩 命令tar zip

    tar  \[主选项+辅选项\] 文件或目录 主选项是必须要有的,它告诉tar要做什么事情。 辅选项是辅助使用的,可以选用。 tar常用命令: 主选项: -x