tar命令不能正确排除文件

时间:2015-10-12 21:06:13

标签: linux unix

今天运行tar命令时,我试图排除文件系统内的文件目录。我跑了这个命令 -

tar --exclude='./my/directory/here' -zcvf backup.tar.gz docroot/

然而,当它在目录中时,它仍然包含来自“here”的文件。如何才能正确排除文件?

我的工作不正常 - 请参阅演示 -

$ sudo tar --exclude='./jsmith/testDirectory/' -zcvf backup.tar.gz ./jsmith/
[sudo] password for jsmith:
./jsmith/
./jsmith/.bash_logout
./jsmith/backup2015-9-8.sql.gz
./jsmith/.mysql_history
./jsmith/.bashrc
./jsmith/testDirectory/
./jsmith/testDirectory/test4.sh
./jsmith/testDirectory/test2.sh
./jsmith/testDirectory/test6.sh
./jsmith/testDirectory/deploy/
./jsmith/testDirectory/test8.sh
./jsmith/testDirectory/tets12.sh
./jsmith/testDirectory/test1.sh
./jsmith/testDirectory/test7.sh
./jsmith/testDirectory/.sh
./jsmith/testDirectory/test9.sh
./jsmith/testDirectory/test11.sh
./jsmith/testDirectory/test10.sh
./jsmith/testDirectory/test3.sh
./jsmith/testDirectory/test5.sh
./jsmith/.viminfo
./jsmith/.drush/
./jsmith/.drush/cache/
./jsmith/.drush/cache/usage/
./jsmith/.drush/cache/default/

1 个答案:

答案 0 :(得分:1)

您的命名需要保持一致!

public class AnotherThing : Thing 
{
    AnotherThing (Thing value)
    {
        this.Property = value.Property;
    }
    public string AnotherProperty {get;set;}
}

......应该是这样的:

tar --exclude='./my/directory/here' -zcvf backup.tar.gz docroot/

...也就是说:如果您不在要包含在tarball中的文件名中使用前导tar --exclude='docroot/my/directory/here' -zcvf backup.tar.gz docroot/ ,则不能使用前导./要排除的文件的名称。 (反之亦然:如果你在文件名中使用./,你也需要在排除模式中使用它。)

观察:

./docroot

值得注意的是,虽然存在$ mkdir -p docroot/my/directory/here/content docroot/other/content $ tar --exclude='./docroot/my/directory/here/' -zcvf backup.tar ./docroot/ a ./docroot a ./docroot/my a ./docroot/other a ./docroot/other/content a ./docroot/my/directory ,但my/directory不存在,my/directory/here也不存在。