⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bzip2-10.html

📁 Linux初学者最好的老师就是howto了。相当于函数man。
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312">
 <META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.9">
 <TITLE>Bzip2 Howto: 使用 bzip2 来再压缩其他的压缩格式</TITLE>
 <LINK HREF="Bzip2-11.html" REL=next>
 <LINK HREF="Bzip2-9.html" REL=previous>
 <LINK HREF="Bzip2.html#toc10" REL=contents>
</HEAD>
<BODY>
<A HREF="Bzip2-11.html">Next</A>
<A HREF="Bzip2-9.html">Previous</A>
<A HREF="Bzip2.html#toc10">Contents</A>
<HR>
<H2><A NAME="s10">10. 使用 bzip2 来再压缩其他的压缩格式</A></H2>

<P>下面的 perl 程式会把以下列的压缩格式档 (.tar.gz, .tgz. .tar.Z, 和 .Z for this iteration)
重新打包成最佳的压缩值。这 perl 原始程式都有全方位的好文件
来说明它做什麽以及它如何办到的。
<PRE>
#!/usr/bin/perl -w

#######################################################
#                                                     #
# This program takes compressed and gzipped programs  #
# in the current directory and turns them into bzip2  #
# format.  It handles the .tgz extension in a         #
# reasonable way, producing a .tar.bz2 file.          #
#                                                     #
#######################################################
$counter = 0;
$saved_bytes = 0;
$totals_file = '/tmp/machine_bzip2_total';
$machine_bzip2_total = 0;

while(&lt;*[Zz]>) {
    next if /^bzip2-0.1pl2.tar.gz$/;
    push @files, $_;
}
$total = scalar(@files);

foreach (@files) {
    if (/tgz$/) {
        ($new=$_) =~ s/tgz$/tar.bz2/;
    } else {
        ($new=$_) =~ s/\.g?z$/.bz2/i;
    }
    $orig_size = (stat $_)[7];
    ++$counter;
    print "Repacking $_ ($counter/$total)...\n";
    if ((system "gzip -cd $_ |bzip2 >$new") == 0) {
        $new_size = (stat $new)[7];
        $factor = int(100*$new_size/$orig_size+.5);
        $saved_bytes += $orig_size-$new_size;
        print "$new is about $factor% of the size of $_. :",($factor&lt;100)?')':'(',"\n";
        unlink $_;
    } else {
        print "Arrgghh!  Something happened to $_: $!\n";
    }
}
print "You've ",
      ($saved_bytes>=0)?"saved":"lost",
      " $saved_bytes bytes of storage space :",
       ($saved_bytes>=0)?")":"(", "\n";

unless (-e '/tmp/machine_bzip2_total') {
    system ('echo "0" >/tmp/machine_bzip2_total');
    system ('chmod', '0666', '/tmp/machine_bzip2_total');
}


chomp($machine_bzip2_total = `cat $totals_file`);
open TOTAL, ">$totals_file"
     or die "Can't open system-wide total: $!";
$machine_bzip2_total += $saved_bytes;
print TOTAL $machine_bzip2_total;
close TOTAL;

print "That's a machine-wide total of ",`cat $totals_file`," bytes saved.\n";
</PRE>
<P>
<HR>
<A HREF="Bzip2-11.html">Next</A>
<A HREF="Bzip2-9.html">Previous</A>
<A HREF="Bzip2.html#toc10">Contents</A>
</BODY>
</HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -