菜鳥學Linux 第024篇筆記 壓縮,tar,read,script

菜鳥學Linux 第024篇筆記  壓縮,tar,read,script



壓縮格式:

gz, bz2, xz, zip, z


壓縮算法: 算法不同,壓縮比也會不同;


command

compress: FILENAME.Z

uncompress

gzip: .gz

壓縮會刪除原文件

-d = gunzip

-# --fast --best

              Regulate the speed of compression using the specified

              digit  #,  where  -1  or --fast indicates the fastest

              compression  method  (less  compression)  and  -9  or

              --best indicates the slowest compression method (best

              compression).  The default compression  level  is  -6

              (that  is, biased towards high compression at expense

              of speed).

gunzip /path/name.gz

解壓縮會刪除原文件

zcat 可以用來查看壓縮的文本文檔.gz


bzip2: .bz2

壓縮會刪除原文件

比gzip擁有更大壓縮比的壓縮工具,使用近似gzip(壓縮大文件的時候)

-d

-#

-k --keep

              Keep (don’t delete) input files during compression or

              decompression.

bunzip2 解壓bz2文件

bzcat 查看壓縮文檔文檔.bz2

xz (壓縮比更大)有的系統沒有需要安裝yum install xz

壓縮會刪除原文件

-d

-#

-k

unxz

xzdec

xzcat


zip(壓縮比不大,但可以支持壓縮目錄)

注意:這個壓縮是不會刪除原文件的!!!

zip,  zipcloak,  zipnote,  zipsplit  -  package and compress

       (archive) files

unzip 解壓

e.g.

zip name.zip test/*

只歸檔不壓縮

command

tar ( tar - The GNU version of the tar archiving utility)

[-]c --create

[-]x --extract --get

-f, --file F

-t, --list

              list the contents of an archive

-v, --verbose

              verbosely list files processed

--xattrs (保留文件的擴展屬性信息)

              this option causes tar to store each file’s  extended

              attributes  in  the archive. This option also enables

              --acls and--selinux if they haven’t been set already,

              due to the fact that the data for those are stored in

              special xattrs.

-z, --gzip, --gunzip, --ungzip

              filter the archive through gzip

-j, --bzip2

              filter  archive through bzip2, use to decompress .bz2

              files

-J --xz(用最新的xz壓縮或解壓縮歸檔文件但需要tar版本)

e.g.

  tar -tf name.tar.gz

查看壓縮歸檔文件包含內容

  tar -xvf foo.tar

              verbosely extract foo.tar


       tar -xzf foo.tar.gz

              extract gzipped foo.tar.gz


       tar -cjf foo.tar.bz2 bar/

              create bzipped  tar  archive  of  the  directory  bar

              called foo.tar.bz2


       tar -xjf foo.tar.bz2 -C bar/

              extract  bzipped foo.tar.bz2 after changing directory

              to bar


       tar -xzf foo.tar.gz blah.txt

              extract the file blah.txt from foo.tar.gz

 

cpio (cpio - copy files to and from archives)歸檔工具



read 命令

可以從用戶接下來所輸入的字符保存到變量裏

e.g.

read A B

1 3 則會將1保存到A變量 3保存到B變量

寫腳本

1.從鍵盤讓用戶輸入幾個文件,腳本能夠將此幾個文件歸檔壓縮成一個文件,

  並且可以自定義壓縮方式;

2.檢查某個用戶,當用戶登錄時顯示該用戶已經登錄;







KEY

1. #!/bin/bash

#

read -p "Three files:" FILE1 FILE2 FILE3

read -p "Save direcotry:" DEST

read -p "Compression type:{gzip|bzip2}" STY

case $STY in

gzip)

 tar -zcf ${DEST}.tar.gz $FILE1 $FILE2 $FILE3

 ;;

bzip2)

 tar -jcf ${DEST}.tar.bz2 $FILE1 $FILE2 $FILE3

 ;;

*)

 echo "Unknown."

 exit 20

 ;;

esac


2. #!/bin/bash

#

who | grep "tom" &> /dev/null 

REC=$?

while [ $REC -ne 0 ]; do

 echo "`date`, tom not in home"

 sleep 5

 who | grep "tom" &> /dev/null 

 REC=$?

done

echo "tom is at home!!"


 


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章