tar 压缩 tar.gz_Linux中的Tar – Tar GZ,Tar文件,Tar目录和Tar压缩命令示例

tar 压缩 tar.gz

Do you want to combine a bunch of files and directories into a single file? The tar command in Linux is what you're looking for!

您是否要将一堆文件和目录合并到一个文件中? 您正在寻找Linux中的tar命令!

The tar command is used to compress a group of files into an archive. The command is also used to extract, maintain, or modify tar archives.

tar命令用于将一组文件压缩为归档文件。 该命令还用于提取,维护或修改tar归档文件。

Tar archives combine multiple files and/or directories together into a single file. Tar archives are not necessarily compressed but they can be. Permissions are preserved and it supports many compression formats.

Tar归档文件将多个文件和/或目录组合在一起成为一个文件。 Tar档案不一定要压缩,但可以压缩。 权限被保留,它支持许多压缩格式。

Learn how to use tar in this quick article.

在此快速文章中了解如何使用tar

句法 (Syntax)

tar [options] [archive-file] [file or directory to be archived]

tar [options] [archive-file] [file or directory to be archived]

Options:-c : Creates archive-x : Extracts the archive-f : creates archive with given filename-t : displays or lists files in archived file-u : archives and adds to an existing archive file-v : Displays verbose information-A : Concatenates the archive files-z : compresses the tar file using gzip-j : compresses the tar file using bzip2-W : Verifies an archive file-r : updates or adds file or directory in already existing .tar file

选项: -c:创建归档文件-x:提取归档文件-f:创建具有给定文件名的归档文件-t:显示或列出归档文件中的文件-u:归档文件并添加到现有归档文件中-v:显示详细信息-A :连接归档文件-z:使用gzip压缩tar文件-j:使用bzip2压缩tar文件-W:验证归档文件-r:在现有的.tar文件中更新或添加文件或目录

使用范例 (Usage Examples)

Extract an archive:tar xfv archive.tar(Options: x = extract, f = file, v = verbose)

提取档案: tar xfv archive.tar (选项:x =提取,f =文件,v =详细)

Create an archive with files or folder:tar cfv archive.tar file1 file2 file3(Options: c = create)

使用文件或文件夹创建档案: tar cfv archive.tar file1 file2 file3 (选项:c =创建)

Create compressed archives:tar cfzv archive.tar file1 file2 file3 (Options: z = compress with gzip)

创建压缩的归档文件: tar cfzv archive.tar file1 file2 file3 (选项:z =使用gzip压缩)

Show all files of an archive:tar tvf archive.tar

显示存档的所有文件: tar tvf archive.tar

Create an uncompressed archive of all .txt files in current directory:tar cfv archive.tar *.txt

创建当前目录中所有.txt文件的未压缩存档: tar cfv archive.tar *.txt

Extract files from gzip tar Archive archive.tar.gz:tar xvzf archive.tar.gz

从gzip tar存档文件archive.tar.gz中提取文件: tar xvzf archive.tar.gz

Create a compressed tar archive file using bzip2:tar cvfj archive.tar.tbz example.cpp(Options: j = compress with bzip2, smaller file size but takes longer than -z)

使用bzip2创建压缩的tar存档文件: tar cvfj archive.tar.tbz example.cpp (选项:j =使用bzip2进行压缩,文件大小较小,但所需时间比-z )

Update existing tar file by adding todo.txt file to archive:tar rvf archive.tar todo.txt(Options: r = add file)

通过将todo.txt文件添加到归档文件来更新现有的tar文件: tar rvf archive.tar todo.txt (选项:r =添加文件)

List contents of tar file:tar tf file.tar(Options: t = display, f = file)

tar文件的列表内容: tar tf file.tar (选项:t =显示,f =文件)

Create a compressed archive of current directory but exclude certain directories:tar --exclude='./folder' --exclude='./upload/folder2' cfzv archive.tar .("folder" and "folder2" are excluded)

创建当前目录的压缩存档,但排除某些目录: tar --exclude='./folder' --exclude='./upload/folder2' cfzv archive.tar . exclude tar --exclude='./folder' --exclude='./upload/folder2' cfzv archive.tar . (不包括“ folder”和“ folder2”)

翻译自: https://www.freecodecamp.org/news/tar-in-linux-example-tar-gz-tar-file-and-tar-directory-and-tar-compress-commands/

tar 压缩 tar.gz

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值