Example 1.
If I want to compress/opt/apache/htdocs this folder, but not the inside Picture folder uploads also compressed.
Can be ruled out with the--exclude of the tar command.
Method
Compress all Catalogs
| The code is as follows |
Copy Code |
| TAR-ZCVF Htdocs.tar.gz/opt/apache/htdocs |
Exclude a Directory
| The code is as follows |
Copy Code |
| TAR-ZCVF htdocs.tar.gz--exclude=/opt/apache/htdocs/uploads/opt/apache/htdocs |
Exclude Multiple directories
| The code is as follows |
Copy Code |
TAR-ZCVF htdocs.tar.gz--exclude=/opt/apache/htdocs/uploads--exclude=/opt/apache/htdocs/cache/opt/apache/htdocs
|
When you compress a directory, sometimes you want to exclude a directory, as shown in the following example:
Example 2.
If there are 3 directories under the test directory, AA, BB, CC
| The code is as follows |
Copy Code |
Drwxr-xr-x 2 root root 4096 Nov 18:48 AA Drwxr-xr-x 2 root root 4096 Nov 18:48 bb Drwxr-xr-x 2 root root 4096 Nov 18:48 cc |
Now want to compress only the AA directory, the commands are as follows:
| The code is as follows |
Copy Code |
| TAR-ZCVF test1118.tar.gz--exclude=bb--EXCLUDE=CC test |
Exclude a file from the same action as the directory