In this post, I would demo how to exclude some files or directories when creating tarballs.
2.1 If you want to exclude specific directory
To exclude specific dir,execute the following command:
2.2 Exclude multiple directories
If you want to exclude multiple directories, you can add –exclude. The following command excludes the logs and libs directories and the file bswen.txt:
tar -zcvf tomcat.tar.gz --exclude=tomcat/logs --exclude=tomcat/libs --exclude=tomcat/bswen.txt tomcat
2.3 Pay attention here
When everyone should pay attention here, when we use tar’s –exclude command to exclude packaging, we cannot add “/”, otherwise the logs directory and the files under it will still be packaged.
tar -zcvf tomcat.tar.gz --exclude=tomcat/logs/ --exclude=tomcat/libs/ tomcat
tar -zcvf tomcat.tar.gz --exclude=tomcat/logs --exclude=tomcat/libs tomcat
In this post, I demonstrated how to package linux directories with some excludes. That’s it, thanks for your reading.