Tar command
Role: packaging, compressing files
[Email protected] ~]# tar--help
Usage:tar [OPTION ...] [FILE] ...
GNU ' tar ' saves many files together into Asingle tape or disk archive, and can
Restore individual files from the archive.
Examples:
tar-cf Archive.tarfoo Bar # Create Archive.tar from Filesfoo and bar.
TAR-TVF Archive.tar # List All files in archive.tarverbosely.
TAR-XF Archive.tar # Extract all files from Archive.tar.
Packaged:
Cases:
[Email protected] ~]# TAR-CVF grub.tar/boot/grub/
Tar:removing leading '/' from member names
/boot/grub/
/boot/grub/ffs_stage1_5
/boot/grub/device.map
/boot/grub/vstafs_stage1_5
...............
Creating #c Create
#v verbose More information
#f filename
Learn about Linux see what the file is type
File Command
function: determine what type of file it belongs to
usage: file file name
[[Email protected] ~]# file Grub.tar
Grub.tar:POSIX Tar archive (GNU)
[Email protected] ~]# TAR-CVF file.txt/boot/grub/
[[Email protected] ~]# file file.txt
File.txt:POSIX Tar archive (GNU)
summarize The file types that cannot be distinguished by a suffix in Linux if you want to view the types of files with the file command
Example: Package two directories or directories + files into a single package
[Email protected] ~]# TAR-CVF ss.tar/boot//etc/passwd
Do not understand the package, view the contents of the TAR package
[Email protected] server63 ~]# TAR-TF Ss.tar
boot/
Boot/symvers-2.6.32-431.el6.x86_64.gz
Boot/config-2.6.32-431.el6.x86_64
boot/efi/
boot/efi/efi/
boot/efi/efi/redhat/
.....
When comparing packaging
[Email protected] ~]# TAR-CVF grub.tar/boot/grub/
Tar:removing leading '/' from member names
content after compression No / start with boot directly
want to view the file details in the package +v Parameters
[Email protected] server63 ~]# TAR-TVF Ss.tar
Dr-xr-xr-x root/root 0 2016-04-21 19:37 boot/
-rw-r--r--root/root 193758 2013-11-22 11:41boot/symvers-2.6.32-431.el6.x86_64.gz
-rw-r--r--root/root 105195 2013-11-22 11:40boot/config-2.6.32-431.el6.x86_64
......
Unpacking: [Email protected] server63 ~]# TAR-XVF Ss.tar
[[email protected] ~]# ls
Anaconda-ks.cfg heartbeat-3-0-958e11be8686.tar.bz2
Boot Install.log
etc Install.log.syslog
Specify the decompression path:
TAR-XF newfile.tar-c/path/to/distdir/
[Email protected] ~]# TAR-XVF ss.tar-c/opt
[Email protected] ~]# ls/opt/
Boot etc
Tar Archive + Compression: GZ
format (suffix name) tar.gz or . tgz
syntax: tar zcvf newfile.tar.gz SOURCE
[Email protected] ~]# tar-zcvfgrub.tar.gz/boot/grub/
Tar:removing leading '/' from member names
/boot/grub/
/boot/grub/ffs_stage1_5
/boot/grub/device.map
/boot/grub/vstafs_stage1_5
....
Contrast
[Email protected] Server ~]# ll-h grub.tar*
-rw-r--r--. 1 root root 270K Apr 10:33grub.tar
-rw-r--r--. 1 root root 101K Apr 11:38grub.tar.gz
decompression: tar zxvf newfile.tar.gz-c/path/to/distdir/
[[Email protected] Server ~]# rm-rf/opt/* # Delete files in/opt directory
Note if rm-rf/opt is to remove the opt directory, You must pay attention to the work .
[Email protected] Server ~]# TAR-ZXVF grub.tar.gz-c/opt
Archive + Compression : bz2
[Email protected] Server ~]# TAR-JCVF grub.tar.bz2/boot/grub/
[Email protected] Server ~]# ll-h grub.tar*
-rw-r--r--. 1 root root 270K Apr 10:33grub.tar
-rw-r--r--. 1 root root 90K Apr 13:20 grub.tar.bz2
-rw-r--r--. 1 root root 101K Apr 11:38grub.tar.gz
Unzip: [Email protected] Server ~]# TAR-JXVF grub.tar.bz2-c/opt/
Zip package Compression command
[Email protected] ~]# zip a.zip/etc/passwd
ADDING:ETC/PASSWD (deflated 60%)
Compress a Directory
[[Email protected]~]# zip- R grub.zip/boot/grub/
Compress a class of files
Zip all.zip *.jpg # compress all . jpg files into one package
Unzip
[[email protected] ~]# unzip grub.zip-d/opt/#-d assigned to directory
Linux file archiving