Jul 12

How to Tar –EXCLUDE directories

I would like to transfer from one hosting (Mediatemple) to another (Resellerzoom) (both of them were doing superb job for 2 years btw) but I don’t want to transfer some of the old files. I tried most of tar –exclude combinations I could find on the forums but they did not work. One of them was an answer to a question “tar, excluding directories recursively ” on linuxquestions.

I believe it was due to Mediatemple’s environment which strictly jails you under your account. I tried to exclude with full path initially but it kept getting all the files.

So I decided to use -v (verbose) argument to show the compressed files in the realtime. This way you can capture instantly if you are making a mistake or not. I was initially doing with:

tar -cvf techsoar.tgz --exclude "/full-path/phones/*" --exclude "/full-path/mobiles/*" ./

Which I realized using with “” was a mistake and furthermore not putting an “=” sign between –exclude=… was also wrong.

So finally I could get it working with this line:

tar -cvf techsoar.tgz --exclude=phones/* --exclude=mobiles/* ./

Leave a Reply