This article is a mirror article of machine translation, please click here to jump to the original article.

View: 2579|Reply: 3

[linux] Linux uses tar to create archive files

[Copy link]
Posted on 1/1/2024 7:20:00 AM | | |
Requirements: There are a lot of files under the site directory, if the transfer will be very slow one by one, if the folder is compressed and it is very time-consuming, how to process all the contents of the folder (including subfolders) into a file and then transfer? You can use the tar command under Linux.

The tar command in Linux is one of the most important commands in file management. It isTape Archivefor creating and extracting archive files. An archive file is a compressed file that contains one or more files bundled together for easier storage and portability. In this guide, we'll show you how to create, list, edit, and extract tar archive files with examples, and cover some of the more commonly used tar command options.

tar command


tar command option

  • -c - This will create an archive file.
  • -x - This option extracts archive files.
  • -f - Specifies the file name of the archived file.
  • -v - This prints the details of any tar operation on the terminal.
  • -t - This lists all the files in the archive.
  • -u - This archives the file and then adds it to the existing archive.
  • -r - This updates the file or directory located inside the .tar file
  • -z - Create tar files using gzip compression
  • -j - Create archive file with bzip2 compression
  • -W - -w option validates the archive file.


Common commands are as follows:



Reference:

The hyperlink login is visible.
The hyperlink login is visible.




Previous:CentOS uses Alibaba Cloud NAS storage
Next:Linux uses split file cutting splits
 Landlord| Posted on 1/1/2024 7:20:35 AM |
Detailed explanation of zip compression and unzip decompression commands in CentOS
https://www.itsvse.com/thread-3698-1-1.html
 Landlord| Posted on 12/13/2024 5:49:34 PM |
options parameter

Basic operation options

-c: Create a new archive file.
-x: Unzip the archive file.
-t: Lists the contents of the archive.
-r: Appends files to existing archives.
-u: Appends only files that are newer than those already in the archive.
-d: Find differences in archive files that are out of sync with the file system.
-A: Append one .tar file to another .tar file.

File selection and exclusion

-f<file>: Specifies the name of the archive file (must be placed at the end of the list of options).
-C<directory>: Switch to the specified directory for operation.
--exclude=<pattern>: Exclude files that match the specified pattern.
--exclude-from=<file>: Read the pattern to be excluded from the specified file.
--exclude-caches: Exclude cache files from the directory.
--exclude-backups: Exclude backup files ending in ~.
--exclude-vcs: Exclude files generated by the version control system (e.g., .git, . svn, etc.).

Compression and decompression options

-z: Compress the archive file with gzip.
-j: Compress the archive file with bzip2.
-J: Compress the archive file with xz.
--lzip: Compress archive files with lzip.
--lzma: Compress archive files with lzma.
--lzop: Compress archive files with lzop.
--zstd: Compress archive files with zstd.
-a: Automatically select the compression method (based on the extension of the archive file, such as .tar.gz, . tar.bz2, etc.).
-I <command>: Compressing or decompressing using a specified compression program.

Output and interaction options

-v: Displays detailed operation procedures (verbose).
--progress: Shows a progress bar (when used with -v).
-w or --interactive: Ask the user for confirmation before each action.
--checkpoint: Displays a checkpoint after processing each file.
--checkpoint-action=<action>: Executes the specified action at the checkpoint, such as echo, dot, etc.
--totals: Displays the total number of bytes processed after the operation ends.
--verbose: Displays the processed information in detail.
--quiet: Output as little information as possible.

File and permission-related options

-p: Preserve the original permissions of the file (when unzipped).
--same-owner: Try to set the extracted file as the original owner (requires superuser privileges).
--no-same-owner: No file owner is set.
--same-permissions: Keep the original permissions of the file (same as -p).
--no-same-permissions: Doesn't keep the original permissions, use the current user's umask to set permissions.
-m: The modification time of the file is not restored when unzipping, but the current time is used.

Archiving management options

-k or --keep-old-files: Keep existing files when unzipping, not overwrite.
--overwrite: Force an existing file to be overwritten when unzipping.
--remove-files: Deletes the original file after successful archiving.
--delete: Deletes the specified file from the archive (gnu tar only).
--keep-newer-files: Keep newer files than in the archive when unzipped.
--listed-incremental=<file>: Create or restore from an incremental backup.

File system and device options

-L <N>: Split archive files larger than N bytes (for tape drives).
--tape-length=<number>: Specifies the tape length (for tape drives).
--multi-volume: Create or restore multi-volume archive files.
-M: Used with --multi-volume to handle multi-volume archive files.
--use-compress-program=<prog>: Use the specified compressor.

Other practical options

--transform=<expression>: Renames files in the archive.
--strip-components=<number>: strips a specified number of path components when unzipping.
--ignore-failed-read: ignore the read error and proceed.
--occurrence=<number>: Select the number of occurrence files in the archive.
-S: Handles sparse files (only archives blocks that are actually used).
--no-recursion: does not recursively enter the directory.
-h or --dereference: Archive the file that the symbolic link points to, not the link itself.

Help and version information

--help: Displays help information.
--version: Displays the version information of the tar.

 Landlord| Posted on 12/13/2024 5:59:12 PM |
Windows uses tar to compress and package folders
https://www.itsvse.com/thread-10896-1-1.html
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com