I am trying to create a tar with follwing command:
tar -cvf myFile.tar -X exclude-files.txt myContentDirectory
and my exclude-file has follwing patterns to exclude:
**/*.bak
**/*.db
**/*.html
But i dont see these file types being excluded out in my tar. What am I doing wrong here?
I found that when i have just one pattern in my exclude-files.txt, lets say only
**/*.bak
it does work. But not with multiple file patterns (EACH ON NEW LINE)
Sometimes it's nice if you are tar zipping a directory (let's say for a backup) and want to exclude a directory. For instance, if you are backing up a project and want to exclude the images directory (for size) or exclude the build or dist directory you can run the linux tar command with the --exclude option.
' --verbose ' (' -v ') shows details about the results of running tar . This can be especially useful when the results might not be obvious. For example, if you want to see the progress of tar as it writes files into the archive, you can use the ' --verbose ' option.
When you create a tar archive of a directory tree the hidden files are normally not included. Here's how to include the hidden files. This way all files are tarred except the . htaccess files.
I think this:
*.bak
*.db
*.html
is the correct format for the exclude file if you want to exclude a particular directory you could do:
some-dir/*.db
Also your command should look like this:
tar -cvf myFile.tar -X exclude-files.txt myContentDirectory
Sorry if this answer is a little late.
tar -cO --exclude=*.bak myContentDirectory | tar -O --delete '*.db' | tar -O --delete '*.html' > myFile.tar
See, what you're doing here is creating the tar, but sending it to stdout instead of to a file then piping that into tar to delete the stuff you don't want, one or more times and finally writing the output to a file.
You can even test it first like this:
tar -cO --exclude=*.bak myContentDirectory | tar -O --delete '*.db' | tar -O --delete '*.html' | tar -tv
Which will spit out a list of all the files remaining in the archive.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With