Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Linux \ Linux Basic Course: tar command description     - Github Getting Started Basic Course (Linux)

- Build Docker based MongoDB replication cluster environment (Database)

- CentOS 6.4 Telecom ADSL dial-up network configuration (Linux)

- Is Linux the most secure operating system (Linux)

- Configuring s3c-linux-2.6.28.6-Real6410 appears Unable to find the QT3 installation (Linux)

- CentOS6.0 successful installation and configuration OpenCV (Linux)

- C ++ hash function (Programming)

- JDK comes with tools jinfo (Linux)

- MongoDB polymerization being given (Database)

- Memcached source installation and configuration under CentOS 6.6 (Server)

- Linux Apache server security (Linux)

- Unix / Linux commonly used to clean up disk space command (Linux)

- CentOS 6.5 boot automatically mount the hard drive (Linux)

- MySQL appears data too long for column 'name' at row 1 to solve (Database)

- How to configure AWStats in Ubuntu Server (Server)

- MongoDB data replication and data slices (Database)

- Android Delete project useless resource file (Programming)

- to install the deployment of LVS under CentOS 7.0 (Server)

- CentOS 7 update source - the use of domestic sources 163 yum (Linux)

- C # how to generate a folder or file automatically rename (Programming)

 
         
  Linux Basic Course: tar command description
     
  Add Date : 2018-11-21      
         
         
         
  Linux tar command is a powerful weapon to archive or distribute files. GNU tar archive package can contain multiple files and directories, but also retain their file permissions, it also supports multiple compression formats. Tar represents "Tape Archiver", this format is POSIX standards.

Tar file format

tar compression levels Description:

No compression is not compressed file ending with .tar.
Gzip Gzip compressed tar format is the most widely used compression formats, it can quickly compress and extract files. Compressed with gzip files usually end with .tar.gz or .tgz. Here are some examples of how to create and extract the tar.gz file.
Bzip2 and Gzip compression format compared Bzip2 provides better compression ratio. Create a compressed file is relatively slow, usually .tar.bz2 end.
Lzip (LAMA) Gzip compression Lizp compression combines the advantages of fast, well and Bzip2 similar (or even better) compression ratio. Despite these advantages, this format is not widely used.
Lzop Compression This option may be compressed tar fastest compression format, and its compression ratio is similar to gzip, but is not widely used.
Common formats are tar.gz and tar.bz2. If you want to quickly compress, then it is to use gzip. If the archive size is more important, is to use tar.bz2.

tar command used to do?

Here are some common situations using the tar command.

Backup server or desktop system
Document Archiving
Software Distribution
 
Installation tar

Most Linux systems are installed by default tar. If not, there is the installation tar command.

CentOS

In CentOS, the root user to execute the following command to install the shell tar.

yum install tar
 
Ubuntu

The following command installs the tar on Ubuntu. "Sudo" command ensures that apt to run commands with root privileges.

sudoapt-get install tar

Debian

The following apt command to install tar on Debian.

apt-get install tar

Windows

tar command can also be used in Windows, you can download it from Gunwin project http://gnuwin32.sourceforge.net/packages/gtar.htm in.

Create tar.gz file

Below are some examples of the tar command running in the shell. Here I will explain these command-line options.

tar pczf myarchive.tar.gz / home / till / mydocuments
This command creates the archive myarchive.tar.gz, including the path / home / till / mydocuments files and directories. Command line options are explained:

[P] This option means "preserve", which indicates that retention tar file ownership and permissions information in the archive.
[C] represents the creation. This option can not be missing when you want to create the file.
[Z] z option is enabled gzip compression.
[F] file option tells tar to create an archive. Without this option tar output will be sent to standard output (LCTT Annotation: If not specified, the default is standard output screen, you obviously do not want to show a bunch of gibberish on the screen, you can usually use a pipe symbol to go to other programs ).
 
Tar command examples

Example 1: backup / etc directory

Create / etc configure a backup directory. Is saved in root directory.

tar pczvf /root/etc.tar.gz / etc

Use tar to back up the / etc directory

To root user run the command to ensure that all of the files in / etc will be included in the backup. This time, I added the [v] option to the command. This option means verbose, it tells tar to display all be included in the archive file name.

Example 2: Backup your / home directory

Create a backup of your home directory. The backup will be saved to the / backup directory.

tar czf /backup/myuser.tar.gz / home / myuser
Replace myuser with your user name. This command, I omit the [p] option, will not save the permissions.

Example 3: file-based MySQL database backup

In most Linux distributions, MySQL database stored in / var / lib / mysql. You can use the following command to view:

ls / var / lib / mysql

MySQL using tar file-based backup

Use tar to back up MySQL data files in order to maintain data consistency, first deactivate the database server. The backup will be written to / backup directory.

1) Create a backup directory

mkdir / backup
chmod600 / backup
2) Stop MySQL, backup with tar and restart the database.

service mysql stop
tar pczf /backup/mysql.tar.gz / var / lib / mysql
service mysql start
ls-lah / backup

MySQL-based backup files

Extract tar.gz file

Extract tar.gz file command is:

tar xzf myarchive.tar.gz
 

tar command options explained

[X] x represents the extraction, the order indispensable when extracting tar files.
[Z] z option tells tar to extract the archive file is gzip format.
[F] This option tells tar to read the contents of an archive from a file, the present case is myarchive.tar.gz.
The above tar command quietly extract tar.gz file, unless there is an error message. If you want to see what files are extracted, then add a "v" option.

tar xzvf myarchive.tar.gz
[V] option means verbose, it will show you extract the file name.

Extract tar.gz file
     
         
         
         
  More:      
 
- Java class loading order (Programming)
- Linux, ls command to achieve (Linux)
- socket busy poll of Linux kernel 3.11 to avoid sleep switch (Linux)
- Open Ubuntu system updates (Linux)
- To install file manager Nautilus 3.12.2 under ubuntu (Linux)
- C language files update in real time (Programming)
- MySQL replication master and slave structure built (Database)
- Ubuntu download install and configure Plank Dock (Linux)
- Ubuntu disable graphics card (Linux)
- IBM Data Studio to use ---- window displays all rows (Database)
- iOS in the event delivery and the responder chain (Programming)
- C ++ type conversion and RTTI (Programming)
- To setup CentOS LAMP environment (Server)
- CentOS modify yum update source (Linux)
- Install and use automated tools Ansible in CentOS 7 (Linux)
- Python system default encoding (Programming)
- sed command (Linux)
- Oracle 11g logical standby achieve BI needs (Database)
- Oracle common internal event tracking number (Database)
- SUSE Linux firewall configuration notes (Linux)
     
           
     
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.