Linux tar compression to exclude a folder, linuxtar compression to exclude
Generally, it is easy to package directly with the tar command. You can directly use tar-zcvf test.tar.gz test.
In many cases, we need to package a directory with dozens of sub-directories and sub-files, we need to exclude one or two directories or files during packaging.
In this case, we can add the -- exclude parameter when packaging with the tar command.
For example:
Take tomcat as an example. to exclude the tomcat/logs directory during packaging, run the following command:
Tar-zcvf tomcat.tar.gz -- exclude = tomcat/logs tomcat
If you want to exclude multiple directories, add the -- exclude command. For example, run the following command to exclude two directories, logs and libs, and the xiaoshan.txt file:
Tar-zcvf tomcat.tar.gz -- exclude = tomcat/logs -- exclude = tomcat/libs -- exclude = tomcat/xiaoshan.txt tomcat
Note:
We all know that linux will automatically complete the directory name when using the tab key, which is very convenient and commonly used.
If we press the tab key when entering tomcat/lo, the command line will automatically generate tomcat/logs/. For the directory, there will be an additional "/"
When we use the tar -- exclude command to exclude packaging, we cannot add "/". Otherwise, we will package the logs directory and its files.
Incorrect syntax:
Tar-zcvf tomcat.tar.gz -- exclude = tomcat/logs/-- exclude = tomcat/libs/tomcat
Correct syntax:
Tar-zcvf tomcat.tar.gz -- exclude = tomcat/logs -- exclude = tomcat/libs tomcat
Package tar in linux to exclude a specific directory (only operate on one directory, not other directories)
Tar-zcf tmp. tgz $ (ls | grep-v dd)
How does the linux zip-r command exclude a subfolder in the folder to be compressed?
Music Video Streaming
Compression
Mv back
: P