linuxtar压缩排除指定⽂件夹
linux tar压缩排除指定⽂件夹
⼀般直接⽤tar命令打包很简单,直接使⽤ tar -zcvf test即可。
在很多时候,我们要对某⼀个⽬录打包,⽽这个⽬录下有⼏⼗个⼦⽬录和⼦⽂件,我们需要在打包的时候排除其中1、2个⽬录或⽂件。这时候我们在⽤tar命令打包的时候,增加参数--exclude就能达到⽬的。
例如:
我们以tomcat 为例,打包的时候我们要排除 tomcat/logs ⽬录,命令如下:
tar -zcvf --exclude=tomcat/logs tomcat
如果要排除多个⽬录,增加 --exclude 即可,如下命令排除logs和libs两个⽬录及⽂件:
tar -zcvf --exclude=tomcat/logs --exclude=tomcat/libs --exclude= tomcat
注意事项:
⼤家都知道linux在使⽤tab键的时候会对⽬录名称⾃动补全,这很⽅便,⼤家也⽐较常⽤。
如我们输⼊ tomcat/lo 的时候按tab键,命令⾏会⾃动⽣成 tomcat/logs/ ,对于⽬录,最后会多⼀个 “/”
这⾥⼤家要注意的时候,在我们使⽤tar 的--exclude 命令排除打包的时候,不能加“/”,否则还是会把logs⽬录以及其下的⽂件打包进去。错误写法:
tar -zcvf --exclude=tomcat/logs/ --exclude=tomcat/libs/ tomcat
linux修改文件夹名称正确写法:
tar -zcvf --exclude=tomcat/logs --exclude=tomcat/libs tomcat