您是否经常在Linux / Ubuntu上压缩和提取文件?您听说过.tar
延期吗?然后,本文供您学习使用tar命令和示例来压缩和提取文件。
在计算中,tar是一种应用程序实用程序,用于将许多记录收集到一个存档文件中,最有可能称为tarball,以进行分发或备份功能。Tar最初是在Unix早期开发的,目的是将记录备份到计算机。基于磁带的存储。它曾经被正式规范化为POSIX标准的一部分。
要获取有关tar的更多信息,请使用以下命令-
$ tar --help
样本输出应如下所示–
Usage: tar [OPTION...] [FILE]... GNU 'tar' saves many files together into a single tape or disk archive, and can restore individual files from the archive. 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. 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 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 .........................................................................................
要创建.tar存档文件,请使用以下命令-
$ tar cvf nhooo.tar /home/linux/12dec
在上面的命令中,它将12dec目录存档,该目录放置在/home/linux/12dec
nhooo.tar中。要验证上述命令,请使用以下命令–
$ ls
样本输出应如下所示–
12dec Documents flaskr Music static nhooo.tarcrawling Downloads intern Pictures templates Videos Desktop flask mozilla.pdf Public Templates
要解压缩.tar存档文件,请使用以下命令–
$ tar -xvf nhooo.tar
样本输出应如下所示–
home/linux/12dec/ home/linux/12dec/final_url_weight.py home/linux/12dec/tp_Crawled_few.txt home/linux/12dec/Final_Url_Weight.csv home/linux/12dec/extracting_keywors.py home/linux/12dec/FINAL_URL_WEIGHT.db home/linux/12dec/site_health_depth5.txt home/linux/12dec/check_ageof_site.py home/linux/12dec/final_url_weight_sqlite.py
要创建.tar.gz存档文件,请使用以下命令-
$ tar czvf nhooo.tar.gz /home/linux/12dec
在上面的命令中,它将12dec目录归档,该目录位于/home/linux/12dec
nhooo.tar中。要验证上述命令,请使用以下命令–
$ ls
样本输出应如下所示–
12dec Documents flaskr Music static nhooo.tar crawling Downloads intern Pictures templates nhooo.tar.gzDesktop flask mozilla.pdf Public Templates Videos
要解压缩.tar.gz存档文件,请使用以下命令-
$ tar -xzvf nhooo.tar.gz
样本输出应如下所示–
home/linux/12dec/ home/linux/12dec/final_url_weight.py home/linux/12dec/tp_Crawled_few.txt home/linux/12dec/Final_Url_Weight.csv home/linux/12dec/extracting_keywors.py home/linux/12dec/FINAL_URL_WEIGHT.db home/linux/12dec/site_health_depth5.txt home/linux/12dec/check_ageof_site.py home/linux/12dec/final_url_weight_sqlite.py
要创建.tar.bz2存档文件,请使用以下命令-
$ tar cjvf nhooo.tar.bz2 /home/linux/12dec
在上面的命令中,它将12dec目录归档,该目录位于/home/linux/12dec
nhooo.tar中。要验证上述命令,请使用以下命令–
$ ls
样本输出应如下所示–
12dec Downloads mozilla.pdf static nhooo.tar.bz2crawling flask Music templates nhooo.tar.gz Desktop flaskr Pictures Templates Videos Documents intern Public nhooo.tar
要解压缩.tar.gz存档文件,请使用以下命令-
$ tar -xjvf nhooo.tar.bz2
样本输出应如下所示–
home/linux/12dec/ home/linux/12dec/final_url_weight.py home/linux/12dec/tp_Crawled_few.txt home/linux/12dec/Final_Url_Weight.csv home/linux/12dec/extracting_keywors.py home/linux/12dec/FINAL_URL_WEIGHT.db home/linux/12dec/site_health_depth5.txt home/linux/12dec/check_ageof_site.py home/linux/12dec/final_url_weight_sqlite.py
要在不同位置提取.tar文件,请使用以下命令-
$ tar -xvf nhooo.tar -C /home/linux/abc
在以上命令中,nhooo.tar存档文件在该/home/linux/abc/
位置提取。样本输出应该是这样的–
home/linux/12dec/ home/linux/12dec/final_url_weight.py home/linux/12dec/tp_Crawled_few.txt home/linux/12dec/Final_Url_Weight.csv home/linux/12dec/extracting_keywors.py home/linux/12dec/FINAL_URL_WEIGHT.db home/linux/12dec/site_health_depth5.txt home/linux/12dec/check_ageof_site.py home/linux/12dec/final_url_weight_sqlite.py
要验证上述命令,请使用以下命令–
/abc/home/linux/12dec$ ls
样本输出应如下所示–
check_ageof_site.py FINAL_URL_WEIGHT.db site_health_depth5.txt extracting_keywors.py final_url_weight.py tp_Crawled_few.txt Final_Url_Weight.csv final_url_weight_sqlite.py
在阅读完本文之后,您将能够了解如何在Linux上使用tar命令压缩和提取文件。在我们的下一篇文章中,我们将提出更多基于Linux的技巧。继续阅读!