How to use tar command to compress and decompress a folder using Win10 cmd

environment:

Win10 Professional Edition

Microsoft Windows [Version 10.0.19041.208]

Problem Description:

How to use tar command to compress and decompress a folder using Win10 cmd

C:\Users\Administrator>tar --help
tar(bsdtar): manipulate archive files
First option must be a mode specifier:
  -c Create  -r Add/Replace  -t List  -u Update  -x Extract
Common Options:
  -b #  Use # 512-byte records per I/O block
  -f <filename>  Location of archive (default \\.\tape0)
  -v    Verbose
  -w    Interactive
Create: tar -c [options] [<file> | <dir> | @<archive> | -C <dir> ]
  <file>, <dir>  add these items to archive
  -z, -j, -J, --lzma  Compress archive with gzip/bzip2/xz/lzma
  --format {
    
    ustar|pax|cpio|shar}  Select archive format
  --exclude <pattern>  Skip files that match pattern
  -C <dir>  Change to <dir> before processing remaining files
  @<archive>  Add entries from <archive> to output
List: tar -t [options] [<patterns>]
  <patterns>  If specified, list only entries that match
Extract: tar -x [options] [<patterns>]
  <patterns>  If specified, extract only entries that match
  -k    Keep (don't overwrite) existing files
  -m    Don't restore modification times
  -O    Write entries to stdout, don't restore to disk
  -p    Restore permissions (including ACLs, owner, file flags)
bsdtar 3.3.2 - libarchive 3.3.2 zlib/1.2.5.f-ipp
命令参数解释
t	显示档案文件列表内容(已压缩的文件)
x	解压档案文件
c	生成档案文件,创建打包文件
f	指定档案文件名称,f必须放在命令参数最后

solution:

1. Compress files

cmd command

tar -cf xxx.tar.gz ./xxx

Package 123.txt file

tar -cf 123.tar.gz ./123.txt

Insert image description herePack 345 folders

tar -cf 345.tar.gz ./345

Insert image description here

2. Unzip the file

cmd command

tar -xf xxx.tar.gz

Unzip the 345.tar.gz file

tar -xf 345.tar.gz

Insert image description here

Guess you like

Origin blog.csdn.net/weixin_42672685/article/details/132900030