How to exclude a Directory with TAR
I need to tar up a directory, and exclude certain files, and certain sub-directories.
The command I'm using is: tar -zcvpf /home/users.tar.gz --directory /home/users --exclude=*.iso* --exclude=*.rpm --exclude=*.mpg --exclude=/home/users/richard --exclude *.tgz . The command excludes files according to defined patterns. Unfortunately, it doesn't exclude the directory /home/users/richard. What is the correct way to exclude a directory with tar? |
|
Yes I did.
It did not work for me. I managed to get it to work though. From outside /home, the following did not work: tar -zcvpf /home/users.tar.gz --directory /home/users --exclude '/home/users/richard/*' . But if I first do: cd /home then do tar -zcvpf /home/users.tar.gz --directory /home/users --exclude 'users/richard/*' . it works. Apparently, you have to first enter the immediate upper directory first. |
please add one more thing
--exclude /home/users/richard/* --exclude /home/users/richard you need to exclude both (the directory as well as the files in that directory) |
All times are GMT -5. The time now is 08:51 PM. |