I. Linux compression and archiving
1. Compression format: GZ, bz2, XZ, zip, Z
2. Compression algorithm: Different algorithm, compression ratio will also be different
3.Linux early compression command: Compress decompression uncompress
4.gzip:. GZ (Cannot compress the directory can only compress files, compressed will delete the original file)
Gzip/path/to/somefile
-D: The same function as the Gunzip command
-#:1-9, specify the compression ratio, the default is 6, compression ratio smaller compression speed faster
Gunzip
Gunzip/path/to/somefile.gz: The original file will be deleted when the decompression is complete
Zcat/path/to/somefile.gz: To view the contents of a text file without being pressed
5.BZIP2:. bz2 (cannot compress the directory can only compress the file, compressed will delete the original file)
Compression tool with a greater compression ratio than gzip, using a format approximation
Bzip2/path/to/somefile
-D: the same function as the bunzip2 command
-#: 1-9, default is 6
-K: Keep the original file when compressing
bunzip2/path/to/somefile.bz2
Bzcat to see the contents of a text file without being pressed
6.XZ:. XZ (default may not be installed, cannot compress the directory can only compress files, compressed will delete the original file )
Xz/path/to/somefile
-D: the same function as the unxz command
-#: 1-9, default is 6
-K: Keep the original file when compressing
UNXZ: Decompression
Xzdec: Unzip-unzip to screen
Xzcat: To view the contents of a text file without being pressed
7.zip: Both archived and compressed tools (can compress the directory)
Zip Filename.zip FILE1 FILE2 ...: Do not delete the original file after compression
Unzip Filename.zip
Archive: Archiving, archiving by itself does not imply compression
8.tar: Archive tool. Tar
-C: Create an archive file
-F File.tar: Archived files for operations
-X: Expand Archive
--xattrs: Preserves extended attribute information for files when archiving
-T: Do not expand the archive to directly see which files are archived
-ZCF: Archive and invoke gzip compression
-ZXF: Call gzip to unzip and expand Archive,-Z option to omit
-JCF: archive and call bzip2 compression
-JXF: bzip2 Extract and expand archive
-JCF: Archive and invoke XZ compression
-jxf: Tune Unzip and expand the archive with XZ
Cpio: Archive Tool
The 9.read command saves the user input values from the keyboard into a variable.
Read
-P "PROMPT" gives a hint
Exercise: Write a script
1. From the keyboard let the user enter two integers, the script can be and output
#!/bin/bash
#
Echo-n "Inpute-intergers:"
Read a B
echo "$a plus $b is: $[$a + $b]"
2. Calculates the and of all positive integers within 100
#!/bin/bash
Declare-i I=1
Declare-i sum=0
While [$I-le 100]; Do
Let sum+= $I
Let i++
Done
Echo $SUM
3. Convert user input characters to uppercase, except for quit:
#!/bin/bash
#
Read-p "Input Something:" STRING
while [$STRING! = ' quit ']; Do
echo $STRING | Tr ' A-Z ' A-Z
Read-p "Input Something:" STRING
Done
4. See if the Hadoop user is logged in every 5 seconds, sign in and sign in and exit; otherwise, the current time is displayed and the Hadoop is not logged in
#!/bin/bash
W.H.O. | grep "Hadoop" &>/dev/null
Retval=$?
While [$RETVAL-ne 0]; Do
echo "' Date ', Hadoop is not log."
Sleep 5
W.H.O. | grep "Hadoop" &>/dev/null
Retval=$?
Done
echo "Hadoop is logged in."
This article is from "Luo Chen's blog" blog, please be sure to keep this source http://luochen2015.blog.51cto.com/9772274/1638617
Linux compression and archiving