Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The usage of tar Compression and decompression Command under Linux

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "the usage of tar compression and decompression command under Linux". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn the usage of the tar compression and decompression command under Linux.

Tar

-c: create compressed files

-x: decompression

-t: view content

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

-u: update the files in the original package

These five are independent commands, one of which should be used for compression and decompression, which 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 and remember that this parameter is the last parameter and can only be followed by the file name.

# tar-cf all.tar * .jpg

This command is to type all .jpg files into a package called all.tar. -c means to generate a new package, and-f specifies the file name of the package.

# tar-rf all.tar * .gif

This command adds all .gif files to the all.tar package. -r means to add files.

# tar-uf all.tar logo.gif

This command updates the logo.gif file in the original tar package all.tar, and-u means to update the file.

# tar-tf all.tar

This command lists all the files in the all.tar package.-t means to list files.

# tar-xf all.tar

This command is to unlock all the files in the all.tar package,-t means to unlock

Compress

Tar-cvf jpg.tar * .jpg / / package all jpg files in the directory into tar.jpg

Tar-czf jpg.tar.gz * .jpg / / package all the jpg files in the directory into jpg.tar and compress them with gzip to generate a gzip compressed package named jpg.tar.gz

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

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

For rar a jpg.rar * .jpg / / rar format, you need to download rar for linux first.

For compression in zip jpg.zip * .jpg / / zip format, you need to download zip for linux first

Decompression

Tar-xvf file.tar / / extract the tar package

Tar-xzvf file.tar.gz / / decompress tar.gz

Tar-xjvf file.tar.bz2 / / decompress tar.bz2

Tar-xZvf file.tar.Z / / decompress tar.Z

Unrar e file.rar / / decompress rar

Unzip file.zip / / decompress zip

Summary

1. Tar is decompressed with tar-xvf

2. *. Gz is decompressed with gzip-d or gunzip

3. * .tar.gz and * .tgz are decompressed with tar-xzf

4. * .bz2 decompress with bzip2-d or bunzip2

5. * .tar.bz2 decompress with tar-xjf

6. * .Z decompress with uncompress

7. Tar.Z is decompressed with tar-xZf

8. *. Rar decompressed with unrar e

9. *. Zip decompressed with unzip

Extract the jdk to the specified folder:

Tar-xzvf jdk-8u131-linux-x64.tar.gz-C / usr/local/java

Root@ubuntu:~# 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 mode of operation:

-A,-- catenate,-- concatenate append tar files to the archive

-c,-- create creates a new archive

-d,-- diff,-- compare find out the difference between archiving and file system

-- delete from Archive (not on tape!) Delete in

-r,-- append appends the file to the end of the archive

-t,-- list lists the contents of the archive

-- test-label test archive volume label and exit

-u,-- update appends only files that are newer than the copy in the archive

-x,-- extract,-- get unpack the file from the archive

Action modifier:

-- check-device checks the device number when creating an incremental archive (default)

-g,-- listed-incremental=FILE handles incremental backups in the new GNU format

-G,-- incremental handles incremental backups in the old GNU format

-- ignore-failed-read

Do not exit with a non-zero value when you encounter an unreadable file

-- output level of the incremental list archive created by level=NUMBER

-n,-- seek archives can be retrieved

-- no-check-device do not check the device number when creating incremental archives

-- no-seek archives cannot be retrieved

-- occurrence [= NUMBER] processes only the NUMBER of each file in the archive

Events; only if with the following subcommand-- delete

-diff,-extract or-list

This option is valid only if you use one of the. And no matter whether the list of files is given on the command line or through

Specified by the-T option; the NUMBER value defaults to 1

-- sparse-version=MAJOR [.minor]

Sets the discrete format version used (implied

-- sparse)

-S,-- sparse efficient processing of discrete files

Rewrite control:

-k,-- keep-old-files don't replace existing files when extracting

Treat them as errors

-- keep-directory-symlink preserve existing symlinks to directories when

Extracting

-- keep-newer-files

Do not replace existing files that are newer than the copy in the archive

-- no-overwrite-dir retains the metadata of existing directories

-- one-top-level [= DIR] create a subdirectory to avoid having loose files

Extracted

-- rewrite existing files when overwrite is decompressed

-- overwrite the metadata of an existing directory when overwrite-dir is decompressed (default)

-- recursive-unlink clears the directory hierarchy before decompressing the directory

-- remove-files deletes files after adding them to the archive

-- skip-old-files don't replace existing files when extracting

Silently skip over them

-U,-- unlink-first deletes files to be rewritten before decompressing them

-W,-- verify attempts to verify the archive after writing

Select the output stream:

-- ignore-command-error ignores the exit code of the child process

-- no-ignore-command-error

Treat the non-zero exit code of the child process as an error

-O,-- to-stdout unzips the file to standard output

-- to-command=COMMAND

Transfer the extracted file to another program through a pipeline

Manipulate file properties:

-- atime-preserve [= METHOD]

Keep the access time on the output file, or by reading the default

METHOD='replace'), or do not set the time for the first time (METHOD='system')

-- clamp-mtime only set time when the file is more recent than

What was given with-mtime

-- delay-directory-restore

The modification time and permissions of the extracted directory are not set until the decompression is finished.

-- group= name forces NAME

As the group owner of the file being added

-- mode=CHANGES forces the added file (symbol) to be changed to permission

CHANGES

-- mtime=DATE-OR-FILE sets the settings for added files from DATE-OR-FILE

Mtime

-m,-- touch do not extract the modification time of the file

-- no-delay-directory-restore

Cancel-the effect of the delay-directory-restore option

-- no-same-owner

Extract the file to be yours (this is the default for ordinary users)

-- no-same-permissions

Use the user's mask bits when extracting permissions from the archive (default is normal user service)

-- numeric-owner always represents the name of a user / group with a number

-- owner= name forces NAME

As the owner of the added file

-p,-- preserve-permissions,-- same-permissions

Extract the file permission information (the default is for superusers only)

-- preserve is the same as-p and-s

-- same-owner

Keep the owner relationship consistent when trying to extract (superuser defaults to this item)

-s,-- preserve-order,-- same-order

Member arguments are listed in the same order as

The files in the archive

-- sort=ORDER directory sorting order: none (default), name or

Inode

Handling of extended file attributes:

-- acls Enable the POSIX ACLs support

-- no-acls Disable the POSIX ACLs support

-- no-selinux Disable the SELinux context support

-- no-xattrs Disable extended attributes support

-- selinux Enable the SELinux context support

-- xattrs Enable extended attributes support

-- xattrs-exclude=MASK specify the exclude pattern for xattr keys

-- xattrs-include=MASK specify the include pattern for xattr keys

Device selection and switching:

-f,-- file=ARCHIVE uses archived files or ARCHIVE devices

-- force-local

Even if there is a copy of the archive file, it is still considered a local archive.

-F,-- info-script= name,-- new-volume-script= name

Run the script at the end of each tape (implied-M)

-L,-- change the tape after tape-length=NUMBER writes NUMBER × 1024 bytes

-M,-- multi-volume create / list / extract multi-volume archive files

-- rmt-command=COMMAND uses the specified rmt COMMAND instead of rmt

-- rsh-command=COMMAND uses remote COMMAND instead of rsh

-- volno-file=FILE uses / updates volumes in FILE

Equipment is divided into blocks:

-b,-- blocking-factor=BLOCKS BLOCKS x 512 bytes per record

-B,-- read-full-records is re-chunked when read (valid for 4.2BSD pipes only)

-I,-- ignore-zeros ignores zero-byte blocks in the archive (that is, the end of the file)

-- record-size=NUMBER the number of bytes per record NUMBER, multiplied by 512

Select the archive format:

-H,-- format=FORMAT creates an archive in the specified format

FORMAT is one of the following formats:

Gnu GNU tar 1.13.x format

Oldgnu GNU format as per tar

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report