Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What is the correct way to use the --remove-files option when using tar?

Is it...

tar -cfvj --remove-files archive.tar.bz2 archive/


tar -cfvj archive.tar.bz2 archive/ --remove-files
share|improve this question
up vote 6 down vote accepted

Since the -f argument is telling tar you are going to speficy the file name of the archive you are acting on, I would keep the archive name right after that argument. The list of files and directories to include in the archive should come last. You can specify --remove-files before your other arguments like this:

tar --remove-files -cvfj archive.tar.bz2 archive/
share|improve this answer
Excellent, thank you kindly. – m.p.c Jun 23 '11 at 11:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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