Get the App
SLTechnology News&Howtos  ›  Network Security  › 

Summary command-tar

Shulou Source: shulou.com Published: 2022-06-01 09:11:43 11月26日 Update

Common parameters of tar

-c: create compressed files

-x: decompression

-t: view content

-r: appends files to the end of the compressed archive file

-u: update the contents of the compressed file

These five are independent commands, and one of them is used for compression and decompression. They can be used with other commands, but only one of them can be used.

The following parameters are optional when compressing or decompressing files as needed

-z: with gzip attribute

-j: with bz2 attribute

-Z: with compress attribute

-v: show all processes

-O: unlock files to standard output

The following parameter-f is required

-f: use the file name. Remember that this parameter is the last parameter and can only be followed by the file name.

Compression command: ending with various types

# compress all compressed files with a suffix of txt and a package ending with tar

# tar-cf a.tar * .txt

# ll a.tar

-rw-r--r-- 1 svnuser svnuser 61440 Apr 21 09:39 a.tar

# append new files to a.tar

# tar-rf a.tar * .bk

# update the file 1.bk in the archive

# tar-uf a.tar 1.bk

# View the files in the a.tar package

# tar-tf a.tar

Compound compression command

Tar-cf a.tar * .txt / / package all jpg files in the directory into tar

Tar-czf b.tar.gz * .txt / / after all the jpg files in the directory are packaged into tar and compressed with gzip, a gzip compressed package is generated that ends with tar.gz.

Tar-cjf c.tar.bz2 * .txt / / package all the txt files in the directory into tar and compress them with bzip2 to generate a bzip2 compressed package that ends with tar.bz2

Tar-cZf d.tar.Z * .txt / / package all the txt files in the directory into tar and compress them with compress to generate a umcompress compressed package that ends with tar.Z

Tar-czf f.tgz * .txt / / package all txt files in the directory as files at the end of tgz

Extract the tar compressed packet

# tar-xf a.tar / / decompress the compressed package at the end of tar

# tar-xzvf b.tar.gz / / decompress the compressed package at the end of tar.gz

# tar-xjvf c.tar.bz2 / / decompress the compressed package at the end of tar.bz2

# tar-xZvf d.tar.Z / / decompress the compressed package at the end of tar.Z

# tar-xzvf f.tgz / / decompress the compressed package at the end of tgz

Tags: File parameter directory command file attribute generation content facet update name suffix common file name end standard procedure stand-alone output Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Microsoft Shulou Technology Apple Huawei