I want to create a GZIP compressed TAR archive containing the contents of /var/log, but excluding /var/log/messages file.

I tried tar -cvf var/log.tar var/log/ -x *.messages*, but got the error message:

tar: You may not specify more  than one `-Acdtrux' or `--test-label' option

Any ideas on how to go about this? I'm pretty confident I can create the archive, just not sure how to exclude the /var/log/messages file.


The -x flag (short for --extract) tells tar to unpack an archive. The -c flag (short for --create) tells tar to create an archive. You're passing both flags, which is a contradiction. It looks like you probably want to use the --exclude flag instead of the -x flag, e.g.:

tar -cvf var/log.tar var/log --exclude='*.messages*'
  • 1
    Thanks! That was a huge help. I ended up doing tar -cvf log.tar /var/log --exclude=/var/log/messages and it worked like a charm. Mar 7 '19 at 2:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.