美文网首页我爱编程
mac 的tar命令--exclude和linux的tar命令-

mac 的tar命令--exclude和linux的tar命令-

作者: 2远 | 来源:发表于2018-05-26 15:30 被阅读0次

    有个需求是压缩某个文件夹,但是要排除该文件夹下的另一个文件夹,于是用到
    --exclude命令,但是在mac上面执行

    tar -zcvf test.tgz test/ --exclude *.jpg

    始终提示

    tar: --exclude: Cannot stat: No such file or directory

    而在linux上面就不会提示这个错误,到底是为什么呢?
    后来发现是mac和linux对这个参数的处理不一样,通过man tar分别查阅mac和linux上面的说明,发现mac上面对于 --exclude是这样解释的

     --exclude pattern
    Do not process files or directories that match the specified pattern.  
    Note that exclusions take precedence over patterns or filenames specified 
    on the command line.
    

    第一句是对这个命令的解释,也就是排除的意思,接下来第二句就是重点了,意思是 --exclude要写在前面,所以mac上面排除某个文件或文件夹要写成

    tar --exclude *.jpg -zcvf test.tgz test/

    再看下linux下面man tar里对 --exclude 的解释

    --exclude=PATTERN
    exclude files, given as a PATTERN
    

    只是解释了这个命令的用法,并没有对其位置有特殊的说明,经过试验也验证了--exclude放在前面和后面都是生效的

    结语:mac和linux平台很多命令都是相似的,但也是有一些区别,不能想当然

    相关文章

      网友评论

        本文标题:mac 的tar命令--exclude和linux的tar命令-

        本文链接:https://www.haomeiwen.com/subject/dcumjftx.html