Exclude files and directories from tar

The example below shows how you can exclude file “somefile.txt” and directory “subfolder6” from the tar command:

cd /myfolder
echo "subfolder1/somefile.txt" > tarex.tmp
echo "subfolder2/subfolder5/subfolder6" >> tarex.tmp
tar cvfX mytarfile.tar tarex.tmp subfolder1 subfolder2 subfolder3
rm tarex.tmp

Leave a Reply

Your email address will not be published. Required fields are marked *

*