Linux tar command usage

Source: Internet
Author: User
Tags bz2

The TAR command creates archives for Linux files and directories. With tar, you can create files (backup files) for a specific file, or you can change files in the file or add new files to the file. Tar was originally used to create archives on tape, and now users can create files on any device. With the tar command, you can package a whole bunch of files and directories into a single file, which is useful for backing up files or combining several files into one file for easy network transmission.

The first thing to understand is two concepts: packaging and compression. Packaging refers to a large number of files or directories into a total file, compression is a large file through some compression algorithm into a small file.

Why should we differentiate between these two concepts? This is due to the many compression programs in Linux that can only be compressed for one file, so that when you want to compress a lot of files, you have to first make a package (Tar command) of the whole bunch of files, and then compress the program (gzip bzip2 command).

Grammar
tar (选项) (参数)
Options
-A或--catenate:新增文件到以存在的备份文件;-B:设置区块大小;-c或--create:建立新的备份文件;-C <目录>:这个选项用在解压缩,若要在特定目录解压缩,可以使用这个选项。-d:记录文件的差别;-x或--extract或--get:从备份文件中还原文件;-t或--list:列出备份文件的内容;-z或--gzip或--ungzip:通过gzip指令处理备份文件;-Z或--compress或--uncompress:通过compress指令处理备份文件;-f<备份文件>或--file=<备份文件>:指定备份文件;-v或--verbose:显示指令执行过程;-r:添加文件到已经压缩的文件;-u:添加改变了和现有的文件到已经存在的压缩文件;-j:支持bzip2解压文件;-v:显示操作过程;-l:文件系统边界设置;-k:保留原有文件不覆盖;-m:保留文件不被覆盖;-w:确认压缩文件的正确性;-p或--same-permissions:用原来的文件权限还原文件;-P或--absolute-names:文件名使用绝对名称,不移除文件名称前的“/”号;-N <日期格式> 或 --newer=<日期时间>:只将较指定日期更新的文件保存到备份文件里;--exclude=<范本样式>:排除符合范本样式的文件。
Instance

Package the files into a tar package:

tar -cvf log.tar log2012.log    仅打包,不压缩! tar -zcvf log.tar.gz log2012.log   打包后,以 gzip 压缩 tar -jcvf log.tar.bz2 log2012.log  

In a folder, a new file is backed up than a date:

tar -N "2018/3/1" -zcvf log.tar.gz test

If the simplest use of tar, just remember the following three ways:

压 缩:tar -jcv -f filename.tar.bz2 要压缩的文件或目录名称查 询:tar -jtv -f filename.tar.bz2解压缩:tar -jxv -f filename.tar.bz2 -C 欲解压缩的目录

Reference from: "Linux Command Encyclopedia"

Linux tar command usage

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.