注意事项:这种压缩方式只对被格式化为NTFS格式的磁盘分区有效。另外,压缩文件虽然可以节省磁盘空间,但是会影响性能,因为Windows在访问这些文件时,需要预先执行额外的解压操作。问题描述:Win10...
注意事项:这种压缩方式只对被格式化为NTFS格式的磁盘分区有效。另外,压缩文件虽然可以节省磁盘空间,但是会影响性能,因为Windows在访问这些文件时,需要预先执行额外的解压操作。
问题描述:
Win10cmd如何试用tar命令压缩和解压文件夹
C:\Users\Administrator>tar--help
tar(bsdtar):manipulatearchivefiles
Firstoptionmustbeamodespecifier:
-cCreate-rAdd/Replace-tList-uUpdate-xExtract
CommonOptions:
-b#Use#512-byterecordsperI/Oblock
-f<filename>Locationofarchive(default\\.\tape0)
-vVerbose
-wInteractive
Create:tar-c[options][<file>|<dir>|@<archive>|-C<dir>]
<file>,<dir>addtheseitemstoarchive
-z,-j,-J,--lzmaCompressarchivewithgzip/bzip2/xz/lzma
--format{ustar|pax|cpio|shar}Selectarchiveformat
--exclude<pattern>Skipfilesthatmatchpattern
-C<dir>Changeto<dir>beforeprocessingremainingfiles
@<archive>Addentriesfrom<archive>tooutput
List:tar-t[options][<patterns>]
<patterns>Ifspecified,listonlyentriesthatmatch
Extract:tar-x[options][<patterns>]
<patterns>Ifspecified,extractonlyentriesthatmatch
-kKeep(don'toverwrite)existingfiles
-mDon'trestoremodificationtimes
-OWriteentriestostdout,don'trestoretodisk
-pRestorepermissions(includingACLs,owner,fileflags)
bsdtar3.3.2-libarchive3.3.2zlib/1.2.5.f-ipp
复制
C:\Users\Administrator>tar--help
tar(bsdtar):manipulatearchivefiles
Firstoptionmustbeamodespecifier:
-cCreate-rAdd/Replace-tList-uUpdate-xExtract
CommonOptions:
-b#Use#512-byterecordsperI/Oblock
-f<filename>Locationofarchive(default\\.\tape0)
-vVerbose
-wInteractive
Create:tar-c[options][<file>|<dir>|@<archive>|-C<dir>]
<file>,<dir>addtheseitemstoarchive
-z,-j,-J,--lzmaCompressarchivewithgzip/bzip2/xz/lzma
--format{ustar|pax|cpio|shar}Selectarchiveformat
--exclude<pattern>Skipfilesthatmatchpattern
-C<dir>Changeto<dir>beforeprocessingremainingfiles
@<archive>Addentriesfrom<archive>tooutput
List:tar-t[options][<patterns>]
<patterns>Ifspecified,listonlyentriesthatmatch
Extract:tar-x[options][<patterns>]
<patterns>Ifspecified,extractonlyentriesthatmatch
-kKeep(don'toverwrite)existingfiles
-mDon'trestoremodificationtimes
-OWriteentriestostdout,don'trestoretodisk
-pRestorepermissions(includingACLs,owner,fileflags)
bsdtar3.3.2-libarchive3.3.2zlib/1.2.5.f-ipp
命令参数解释
t 显示档案文件列表内容(已压缩的文件)
x 解压档案文件
c 生成档案文件,创建打包文件
f 指定档案文件名称,f必须放在命令参数最后
解决方案:
1.压缩文件
cmd命令
tar-cfxxx.tar.gz./xxx
例如:打包123.txt文件
tar-cf123.tar.gz./123.txt
例如:打包345文件夹
tar-cf345.tar.gz./345
2.解压文件
cmd命令
tar-xfxxx.tar.gz
例如:解压345.tar.gz文件
tar-xf345.tar.gz
压缩文件与解压缩文件并指定路径
如果想指定解压缩后的文件夹,请看第三步
第一步:进入解压文件所在的当前文件夹内右键点击在终端打开
如下图
第二步:在终端内输入命令行(分为两种情况)
此步骤分为两种情况
2.1情况一{文件后缀为.tar.gz}
##xxx为你要解压缩的文件名
tar-zxvfxxx.tar.gz
2.1情况二{文件后缀为.tar}
##xxx为你要解压缩的文件名
tar-zxvfxxx.tar
第三步:输入完毕按回车3.1解压缩后指定路径
##解压缩-将file1.tar.gz解压到testFileName下
tar-xzvffile1.tar.gz-C/testFileName
3.1压缩后指定路径
##压缩-将file2压缩到xxx.tar.gz
##其中xxx为自定义文件名
tar-czvfxxx.tar.gzfile2