Linux Tar Command Concise Tutorial

Personal blog original text: Linux_Tar_ command concise tutorial

Tar is a (compressed) archive tool in Linux.

Archiving means the same as packaging, which is to package a file or directory or multiple files and directories into one file for easy transmission. Usually the compression operation is performed during the packaging process, so tar also comes with compression options. Compressed files are smaller for easy network transmission and reduce waiting time.

Option 1

The first option argument to tar must be one of the following (Acdrtux):

-c, --create
create a new archive
-x, --extract
extract files from archive
-t, --list
list archive contents

Option 2

-C, --directory DIR
change directory to DIR
-f, --file ARCHIVE
use archive file
-j, --bzip2
process .bz2 files (compress/decompress)
-J, --xz
process .xz files (compress/decompress) unzip)
-O, --to-stdout
extract files to stdout (usually the monitor)
-v, --verbose
detail processing of each file
-z, --gzip, --ungzip
process .zip files (compress/decompress)

Example

Create archive from files foo and bar archive.tar
tar -cf archive.tar foo bar
-c create new archive
-f ARCHIVE use archive
create archive from directory /home/demo/ demo.tar
tar -cf demo.tar/ home/demo/
-c create new archive
-f ARCHIVE use archive
If you want to see how each file is processed, add the -v option.
list all files in archive.tar in detail
tar -tvf archive.tar
-t list archive contents
-v show file details
-f ARCHIVE use archive file
extract all files in
archive.tar tar -xf archive.tar
-x extract archive
-f ARCHIVE use archive
If you want to see how each file is processed, add the -v option.
Create gzip compressed archive from directory /home/demo/ demo.tar.gz
tar -czf demo.tar.gz /home/demo/
-c create new archive
-z process zip compression
-f ARCHIVE use archive
if you want to see To process each file, you can add the -v option.
Create gzip compressed archive from multiple directories /home/demo1 /home/demo2 and file hi.txt demo.tar.gz
tar -czf demo.tar.gz /home/demo1 /home/demo2 hi.txt
-c create new archive files
-z process zip compression
-f ARCHIVE use archive files
If you want to see the process of each file, you can add the -v option.
Create bzip2 compressed archive from directory /home/demo demo.tar.bz2
tar -cjf demo.tar.gz /home/demo
-c create new archive
-j process bzip2 compressed file
-f ARCHIVE use archive
if you want to see For each file processing process, you can add the -v option.
bzip2 compresses files smaller than gzip, but takes longer to
compress Extract the contents of gzip compressed archive test.tar.gz to the specified directory /home/demo/
tar -xzf test.tar.gz -C /home/demo/
- x extract archive contents
-z process gzip archives
-f ARCHIVE use archive
-C DIR: change directory to DIR

Extract the contents of the bzip2 compressed archive test.tar.bz2 to the specified directory /home/demo/
tar -xjf test.tar.bz2 -C /home/demo/
-x extract the contents of the archive
-j process the bzip2 compressed file
-f ARCHIVE use Archive-
C DIR: Change directory to DIR

Extract the contents of the xz compressed archive test.tar.xz to the specified directory /home/demo/
tar -xJf test.tar.xz -C /home/demo/
-x extract the archive contents
-J process the xz compressed file
-f ARCHIVE use Archive-
C DIR: Change directory to DIR

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324686865&siteId=291194637