5

I'm trying to tar a whole directory except some subdirs..

The dir my-base-dir is zipped but the excluded dirs/files are also included?

tar -cf my-base-dir/bak/site/site.tar my-base-dir --exclude=my-base-dir/bak/db/* --exclude=my-base-dir/bak/site/*

The excluded paths are correct relative to the current working dir.. Because the output tar file is put in one of them

1 Answer 1

14

You have to put --exclude option before the list of file names to put into (or get out of) the archive i.e.

tar --exclude='my-base-dir/bak/db/*' --exclude='my-base-dir/bak/site/*' -cf my-base-dir/bak/site/site.tar my-base-dir

or you can also use:

tar -cf my-base-dir/bak/site/site.tar --exclude='my-base-dir/bak/db/*' --exclude='my-base-dir/bak/site/*' my-base-dir
1
  • When i want to exclude content of the sub-directories inside uploads folder without excluding empty folders itself, can i do it without using --exclude-from file? --exclude='/name/uploads/*/*' does not work.
    – 16851556
    Jan 8 at 9:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .