日期:2014-05-16  浏览次数:21016 次

Linux瀛︿範璁板綍--鏂囦欢鍘嬬缉

鏂囦欢鍘嬬缉

鏈哄櫒璇█涓庣▼搴忚瑷€

瀵逛簬鏈哄櫒鏉ヨ鍙兘璇嗗埆0,1锛屾垜浠鏋滆鏈哄櫒杩愯蹇呴』杈撳叆鏈哄櫒鑳藉璇嗗埆鐨勮瑷€锛屽彲鏄満鍣ㄨ瑷€涓嶅埄浜庝汉浠娇鐢ㄥ彲鐞嗚В锛屽洜姝ょ瀛﹀灏卞紑鍙戝嚭浜虹被鑳界湅鐨勬噦鐨勭▼搴忚瑷€锛岀劧鍚庡啀鍒涢€犲嚭鈥滅紪璇戝櫒鈥濆皢绋嬪簭璇█杞崲涓烘満鍣ㄨ瑷€銆?/p>

鍘嬬缉鐨勭畝鍗曞師鐞?/h2>

鎴戜滑閮界煡閬?byte=8bit. 姣斿锛屽浜庤繖1杩欎釜鏁板瓧鏉ヨ鍙互琛ㄧず涓?000 0001锛屽墠7涓猙it閮芥槸鈥滅┖鐨勨€濆彧鏈夋渶鍚庝竴涓猙it锛屾湁瀹為檯鎰忎箟銆傚帇缂╃殑鍘熺悊灏辨槸閫氳繃澶嶆潅鐨勮绠楁柟寮忓皢杩欎釜鈥滅┖鐨勨€滃唴瀹瑰敖鍙兘鐨勫幓鎺変互鍑忓皯鏂囦欢鐨勫瓨鍌ㄧ┖闂?/p>

甯歌鍘嬬缉|鎵撳寘鍛戒护

Linux甯歌鐨勫帇缂╁懡浠ゅ紡gzip,bzip2,杩欎簺鍘嬬缉鍛戒护閮芥槸閽堝浜庝竴涓枃浠惰繘琛屽帇缂╋紝鍥犳褰撹鍘嬬缉寰堝鏂囦欢鏃讹紝灏遍渶瑕佸厛杩涜鎵撳寘锛坱ar锛夌劧鍚庡啀杩涜鍘嬬缉銆?/p>

*.Z :compress 绋嬪簭鍘嬬缉鐨勬枃浠?/p>

*.gz:gzip绋嬪簭鍘嬬缉鐨勬枃浠?/p>

*.bz2:bzip2绋嬪簭鍘嬬缉鐨勬枃浠?/p>

*.tar:鎵撳寘鏂囦欢锛屽苟鏈繘琛屽帇缂?/p>

*.tar.gz:鎵撳寘鏂囦欢骞朵互gzip绋嬪簭鍘嬬缉鎵撳寘鏂囦欢

*tar.bz2: 鎵撳寘鏂囦欢骞朵互bzip2绋嬪簭鍘嬬缉鎵撳寘鏂囦欢

gzip

gzip鍙互瑙e紑compress,zip,gzip绛夎蒋浠跺帇缂╃殑鏂囦欢

璇硶锛?/strong>gzip[cdtv#] 鏂囦欢鍚?/p>

閫夐」涓庡弬鏁帮細

-c: 灏嗗帇缂╂暟鎹緭鍑哄埌灞忓箷涓?/p>

-d:瑙e帇缂?/p>

-t:鍙互妫€楠屼竴涓帇缂╂枃浠剁殑涓€鑷存€э紝鐪嬫枃浠舵湁鏃犻敊璇?/p>

-v:鏄剧ず婧愭枃浠?鍘嬬缉鏂囦欢鐨勫帇缂╂瘮绛変俊鎭?/p>

-#:鍘嬬缉绛夌骇锛?1鏈€蹇紝-9鏈€鎱紝榛樿鍊兼椂-6

涓句緥1锛氬帇缂╂枃浠?/strong>

[root@bogon ~]# cp /etc/man.config /tmp/man.config
[root@bogon ~]# gzip -v /tmp/man.config 
/tmp/man.config:         56.1% -- replaced with /tmp/man.config.gz
[root@bogon ~]# ll /etc/man.config /tmp/man.config.gz 
-rw-r--r-- 1 root root 4617 2012-05-30 /etc/man.config
-rw-r--r-- 1 root root 2057 02-27 22:26 /tmp/man.config.gz

涓句緥2锛氳В鍘嬬缉

[root@bogon ~]# gzip -d /tmp/man.config.gz 
[root@bogon ~]# ll  /tmp/man.config 
-rw-r--r-- 1 root root 4617 02-27 22:26 /tmp/man.config

涓句緥3锛氭暟鎹祦閲嶅畾鍚?鍘嬬缉鍚庝繚鐣欏師鏉ユ枃浠?

[root@bogon ~]# gzip -c /tmp/man.config > /tmp/man.config.gz 
[root@bogon ~]# ll /tmp/man.config /tmp/man.config.gz
-rw-r--r-- 1 root root 4617 02-27 22:26 /tmp/man.config
-rw-r--r-- 1 root root 2057 02-27 22:31 /tmp/man.config.gz

鍙互zcat鏉ヨ鍙栫敱gzip鍘嬬缉鐨勬枃浠?/strong>

[root@bogon ~]# zcat /tmp/man.config.gz

bzip2

bzip2鐨勫帇缂╂瘮姣攇zip杩樿濂?/p>

璇硶锛?/strong>bzip2[-cdkzv#] 鏂囦欢鍚?/p>

閫夐」涓庡弬鏁帮細

-c:灏嗗帇缂╂暟鎹緭鍑哄埌灞忓箷涓?/p>

-d:瑙e帇缂?/p>

-k:淇濈暀鍘熷鏂囦欢

-z:鍘嬬缉

-v:鏄剧ず婧愭枃浠?鍘嬬缉鏂囦欢鐨勫帇缂╂瘮绛変俊鎭?/p>

-#:鍘嬬缉绛夌骇锛?1鏈€蹇紝-9鏈€鎱?/p>

鍙互bzcat鏉ヨ鍙栫敱bzip2鍘嬬缉鐨勬枃浠?/strong>

tar

璇硶锛?/strong>

鎵撳寘涓庡帇缂╋細tar [-j|-z] [-cv] [-f 鏂板缓鐨勬枃浠跺悕] filename

鏌ョ湅鏂囦欢鍚嶏細tar [-j|-z] [-tv] [-f 鏂板缓鐨勬枃浠跺悕]

瑙e帇缂╋細tar [-j|-z] [-xv] [-f 鏂板缓鐨勬枃浠跺悕] [-C 鐩綍]

閫夐」涓庡弬鏁帮細

-c:鏂板缓鎵撳寘鏂囦欢

-t:鏌ョ湅鎵撳寘鏂囦欢鍐呭

-x:鍔犲帇缂╂墦鍖呮枃浠?/p>

-j:浣跨敤bzip2杩涜鍘嬬缉/瑙e帇缂?/p>

-z:浣跨敤璇zip杩涜鍘嬬缉/瑙e帇缂?/p>

-v:鍦ㄥ帇缂╄繃绋嬩腑锛屽皢姝e湪澶勭悊鐨勬枃浠跺悕鏄剧ず鍑烘潵

-f filename:闇€瑕佽鍘嬬缉鎴?瑙e帇缂?鐨勬枃浠跺悕

-C:瑙e帇缂╁埌鐨勭洰褰?/p>

-p:淇濈暀澶囦唤鏁版嵁鐨勫師鏈夋潈闄愬拰灞炴€?/p>

-P:淇濈暀缁濆璺緞

--exclude=File:鍦ㄥ帇缂╀腑涓嶅皢FILE鎵撳寘

--newer-mtime=鈥濇椂闂粹€濓細鎵撳寘姣旀寚瀹氭椂闂存柊鐨勬枃浠?/p>

涓句緥1:瀵规枃浠舵墦鍖呭帇缂?/strong>

[root@localhost ~]# tar -jcv -f /root/etc.tar.bz2 /etc
鈥︹€﹀帇缂╂枃浠朵俊鎭?
[root@localhost ~]# tar -zcv -f /root/etc.tar.gz /etc
鈥︹€﹀帇缂╂枃浠朵俊鎭?
[root@localhost ~]# ll --block-size=M /root/etc.tar.bz2 /root/etc.tar.gz ;du -sm /etc
-rw-r--r-- 1 root root 10M 02-28 10:42 /root/etc.tar.bz2
-rw-r--r-- 1 root root 16M 02-28 10:43 /root/etc.tar.gz
179     /etc

鍙互鐪嬪埌鍘嬬缉鍚庯紝鏂囦欢灏忎簡寰堝