Labels

Linux (46) network (13) troubleshoot (13) command (10) virtualization (10) ubuntu (9) Windows (8) cisco (7) security (7) router (6) Tools (5) software (5) vmware (5) ospf (3) eigrp (1) zimbra (1)

2010年1月27日

Linux - Compression and Uncompression Example

compress
compress bigfile     <--------- compress bigfile to be bigfile.Z, bigfile will be disappear.
compress -r myfolder     <---------compress all file to be .Z file in myfolder
compress -c bigfile     <---------display the result to stdout
compress -c bigfile > smallfile.Z      <---------by which, unchange bigfile but saveas another compressed file(smallfile.Z).

uncompress
uncompress smallfile.Z

gzip
gzip bigfile     <--------- compress bigfile to be bigfile.gz
gzip -9 bigfile     <--------- compress bigfile to be bigfile.gz, -9 is best quality but slowest, -1 is the fastest but low compress, default is -6.
gzip -c bigfile > smallfile.gz      <--------- unchange bigfile but save as another compressed file(smallfile.gz).

gunzip
gunzip smallfile.gz     <--------- extract the gz file
gunzip -c smallfile.gz > file     <--------- extract smallfile.gz to a file,and don't smallfile.gz

zcat

zcat smallfile.gz     <---------see the file content without unzip

bzip2, bunzip2, bzcat

bzip2 default compress level 2
the usage is like gzip, gunzip, zcat
(Hints: gzip is better than compress, bzip2 is the best)



tar
option:
-c               create, write tarfile
-t                list content
-z               use gzip compress
-j               use bzip2 compress
-x              extract or restore
-v              view progress
-p              Restore the named files to their original modes, and ACLs if applicable

Example
tar -cf testfolder.tar /path/to/testfolder         <---------------Create tar file
tar -xvf testfolder.tar -C /path/to/folder         <-----------Extract tar file to another folder

Tar & gzip
tar -zpcvf testfolder.tar.gz /path/to/testfolder     <----------Tar and gzip a folder
tar -zpcvf testfolder.tar.gz --exclude=/path/to/testfolder/subfolder1 /path/to/testfolder     <----------Tar and gzip a folder except subfolder1
tar -zxvf testfolder.tar.gz -C /path/to/folder     <----------Extract the file to another
tar -ztf testfolder.tar.gz     <----------View the content

Tar & bzip2

tar -jpcvf testfolder.tar.bz2 /path/to/testfolder     <----------Tar and gzip a folder
tar -jpcvf testfolder.tar.bz2 --exclude=/path/to/testfolder/subfolder1 /path/to/testfolder     <----------Tar and bzip2 a folder except subfolder1
tar -jxvf testfolder.tar.bz2 -C /path/to/folder     <----------Extract the file to another
tar -jtf testfolder.tar.bz2     <----------View the content

dump
for example: lets backup the partition /boot
dump -S /boot                   <---------------------Show how many size will be used
dump -0uf /home/myfolder/boot.dump /boot   <-----------dump the whole partition, 0 is compress level, u means update record to /etc/dumpupdate, f is specify the file name
dump -0j -f /home/myfolder/boot.dump /boot   <-----------bump the whole partition with bzip2 compress.

restore
restore -tf /home/myfolder/boot.dump <---------------- View the dump file content
restore -rf /home/myfolder/boot.dump <---------------- Restore with dump file.

沒有留言:

張貼留言