LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
12
返回列表 发新帖
楼主: harold

自动解压器

[复制链接]
发表于 2009-6-12 00:10:27 | 显示全部楼层
Post by imghch;1994968
参数不用这么复杂吧,xf 就可以解决大部分问题了


把新版tar更新了咯...
回复 支持 反对

使用道具 举报

发表于 2009-8-16 01:38:22 | 显示全部楼层
要自动解压的话,可以试试sEx软件
回复 支持 反对

使用道具 举报

发表于 2009-8-16 07:32:57 | 显示全部楼层
Post by hamika;2016773
要自动解压的话,可以试试sEx软件


此乃什麼玩意?
回复 支持 反对

使用道具 举报

发表于 2010-10-7 20:31:00 | 显示全部楼层
参考arch官方论坛某贴和这个帖子,再从不知某处扒了个unzip的perl实现,自己做了一个perl脚本
用perl的Archive::Zip模块是为了处理中文zip不产生乱码
  1. #!/usr/bin/perl -w
  2. #########################################################################
  3. # Author: stesen
  4. # Created Time: Thu 07 Oct 2010 05:31:52 PM CST
  5. # File Name: e.pl
  6. # Description: try to decompress files
  7. #########################################################################
  8. #use strict;
  9. use Archive::Zip;
  10. use Encode qw(decode encode);
  11. my ($archive, $basenme, $bh, $fh);
  12. foreach $archive (@ARGV) {
  13.     $archive =~ m/\b([^\.]*)\..*\b/;
  14.     $fh = $1;
  15.     $fh =~ s/\s//g;
  16.     if (-e $archive) {
  17.         if ($archive =~ m/(\.tar\.bz2)|(\.tar\.gz)|(\.tar)|(\.tgz)|(\.tbz2)\b/) {
  18.             system "time", "-p", "tar", "xvf", $archive;
  19.         } elsif ($archive =~ /\.bz2\b/) {
  20.             system "time", "-p", "bunzip2", $archive;
  21.         } elsif ($archive =~ m/\.rar\b/i) {
  22.             system "mkdir", "-v", $fh;
  23.             system "time", "-p", "unrar", "x", $archive, $fh;
  24.         } elsif ($archive =~ /\.gz\b/) {
  25.             system "time", "-p", "gunzip", $archive;
  26.         } elsif ($archive =~ m/(\.zip)|(\.jar)\b/i) {
  27.             system "mkdir", "-v", $fh;
  28.             chdir("$fh") or die "$!";
  29.             &uzip("../$archive");
  30.             chdir("..");
  31.         } elsif ($archive =~ /\.Z\b/) {
  32.             system "time", "-p", "uncompress", $archive;
  33.         } elsif ($archive =~ /\.7z\b/) {
  34.             system "time", "-p", "7z", "x", $archive;
  35.         } elsif ($archive =~ /.xz\b/) {
  36.             system "time", "-p", "xz", "-d", $archive;
  37.         } else {
  38.             print("don\'t know how to extract" . $archive . "..."."\n");
  39.         }
  40.     } else {
  41.         print("$archive is not a valid file!" . "\n");
  42.     }
  43. }
  44. sub uzip {
  45.     my ($zip, $from, $to);
  46.     $zip = Archive::Zip->new($_[0]);
  47.     $from = $_[1] || 'utf-8';
  48.     $to = $_[2] || 'utf-8';
  49.     for ($zip->memberNames()) {
  50.         $member = $zip->memberNamed($_);
  51.         $_ = encode($to, decode($from, $_));
  52.         $zip->extractMember($member, $_);
  53.     }
  54. }
复制代码
回复 支持 反对

使用道具 举报

发表于 2010-10-7 20:32:23 | 显示全部楼层
参考arch官方论坛某贴和这个帖子,再从不知某处扒了个unzip的perl实现,自己做了一个perl脚本
用perl的Archive::Zip模块是为了处理中文zip不产生乱码
  1. #!/usr/bin/perl -w
  2. #########################################################################
  3. # Author: stesen
  4. # Created Time: Thu 07 Oct 2010 05:31:52 PM CST
  5. # File Name: e.pl
  6. # Description: try to decompress files
  7. #########################################################################
  8. #use strict;
  9. use Archive::Zip;
  10. use Encode qw(decode encode);
  11. my ($archive, $basenme, $bh, $fh);
  12. foreach $archive (@ARGV) {
  13.     $archive =~ m/\b([^\.]*)\..*\b/;
  14.     $fh = $1;
  15.     $fh =~ s/\s//g;
  16.     if (-e $archive) {
  17.         if ($archive =~ m/(\.tar\.bz2)|(\.tar\.gz)|(\.tar)|(\.tgz)|(\.tbz2)\b/) {
  18.             system "time", "-p", "tar", "xvf", $archive;
  19.         } elsif ($archive =~ /\.bz2\b/) {
  20.             system "time", "-p", "bunzip2", $archive;
  21.         } elsif ($archive =~ m/\.rar\b/i) {
  22.             system "mkdir", "-v", $fh;
  23.             system "time", "-p", "unrar", "x", $archive, $fh;
  24.         } elsif ($archive =~ /\.gz\b/) {
  25.             system "time", "-p", "gunzip", $archive;
  26.         } elsif ($archive =~ m/(\.zip)|(\.jar)\b/i) {
  27.             system "mkdir", "-v", $fh;
  28.             chdir("$fh") or die "$!";
  29.             &uzip("../$archive");
  30.             chdir("..");
  31.         } elsif ($archive =~ /\.Z\b/) {
  32.             system "time", "-p", "uncompress", $archive;
  33.         } elsif ($archive =~ /\.7z\b/) {
  34.             system "time", "-p", "7z", "x", $archive;
  35.         } elsif ($archive =~ /.xz\b/) {
  36.             system "time", "-p", "xz", "-d", $archive;
  37.         } else {
  38.             print("don\'t know how to extract" . $archive . "..."."\n");
  39.         }
  40.     } else {
  41.         print("$archive is not a valid file!" . "\n");
  42.     }
  43. }
  44. sub uzip {
  45.     my ($zip, $from, $to);
  46.     $zip = Archive::Zip->new($_[0]);
  47.     $from = $_[1] || 'utf-8';
  48.     $to = $_[2] || 'utf-8';
  49.     for ($zip->memberNames()) {
  50.         $member = $zip->memberNamed($_);
  51.         $_ = encode($to, decode($from, $_));
  52.         $zip->extractMember($member, $_);
  53.     }
  54. }
复制代码
回复 支持 反对

使用道具 举报

发表于 2010-10-7 20:33:20 | 显示全部楼层
怎么重复发了两遍?版主通知帮忙删掉一个
回复 支持 反对

使用道具 举报

发表于 2010-10-23 23:40:17 | 显示全部楼层
tar xvf可以自动识别.tar.gz和.tar.bz2
回复 支持 反对

使用道具 举报

发表于 2010-10-25 14:05:13 | 显示全部楼层
7zip 的格式加下吧
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表