如何在 Perl 中像 tar 那样在 UNIX 中归档目录? [英] How can I archive a directory in Perl like tar does in UNIX?
问题描述
我想归档一个目录(我不知道我是否可以调用我想压缩一个目录").当我解压缩它时,我想保留另一端的访问权限.我应该用 perl 解决这个问题.
I want to archive a directory (I don't know whether I can call "I want to tar a directory"). I want to preserve the access permissions at the other end when I un-tar it. I should I tackle this problem in perl.
感谢您的回复,但为什么我要求这样做 Perl 是我希望它独立于平台.我想将一个大文件传输到多台机器.这些机器可以是任何平台.我应该能够正确解压这个 tar 文件,对吗?所以我想编写自己的 tar 和 untar 程序.为什么我使用 Perl 是为了让它独立于平台.所以我不能通过在脚本和类似的东西中打开 shell 来使用 tar 命令.Archive::Tar 模块仅处理 tarred 文件,但没有存档文件的选项.
Thanks for the response but why I'm asking for doing it Perl is I want it independent of the platforms. I want to transfer one big file to multiple machines. Those machines can be of any platform. I should be able to untar this tar file properly right? So I want to write my own tar and untar programs. Why I'm using Perl is to make it platform independent. So I can not use tar command by opening the shell in script and stuff like that. The Archive::Tar module only deals with tarred file but it has no option to archive files.
推荐答案
这是一个简单的例子:
#!/usr/bin/perl -w
use strict;
use warnings 'all';
use Archive::Tar;
# Create a new tar object:
my $tar = Archive::Tar->new();
# Add some files:
$tar->add_files( </path/to/files/*.html> );
# */ fix syntax highlighing in stackoverflow.com
# Finished:
$tar->write( 'file.tar' );
# Now extract:
my $tar = Archive::Tar->new();
$tar->read( 'file.tar' );
$tar->extract();
这篇关于如何在 Perl 中像 tar 那样在 UNIX 中归档目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!