user3750910
user3750910

Reputation: 3

Compress a folder and exclude sub-directories in terminal

I'm trying to compress a folder using the command below and exclude multiple sub-folders as it has over 10GBs which i don't need:

    ubuntu@ip-172-31-X-XXX:/var/www$ tar -zcvf master16march.tar.gz master -x "master/media/com_easysocial/photos/*" "master/media/com_easysocial/avatars/*" "master/media/com_easysocial/tmp/*" "master/media/com_easydiscuss/attachments/*" "master/images/joomcareer/*"

And i got this error:

    tar: You may not specify more than one `-Acdtrux' or `--test-label' option
    Try `tar --help' or `tar --usage' for more information.

Upvotes: 0

Views: 2713

Answers (1)

tmp
tmp

Reputation: 1127

You should use --exclude (not -x) and repeat this long option before every pattern, like:

tar -zcvf master16march.tar.gz master --exclude "master/media/com_easysocial/photos/*" --exclude "master/media/com_easysocial/avatars/*" --exclude "master/media/com_easysocial/tmp/*" --exclude "master/media/com_easydiscuss/attachments/*" --exclude "master/images/joomcareer/*"

Alternatively you can use -X to point to a file containing exclude patterns.

If you want to exclude folders entirely (not only files), use folder path without wildcards, like:

tar -zcvf master16march.tar.gz master --exclude "master/media/com_easysocial/photos" --exclude "master/media/com_easysocial/avatars" --exclude "master/media/com_easysocial/tmp" --exclude "master/media/com_easydiscuss/attachments" --exclude "master/images/joomcareer" 

Upvotes: 2

Related Questions