I'd like to change the command I'm actualy using to put files in a tar archive in order to achieve this:

1) Remove directories tree from the archive (actually the .tar.gz file mantains the tree of the files. I want the files to be "parent").

2) Remove the files used to create the archive and leave only the new .tar.gz

BACKUP_DEST=/home/backup/db/`date +\%G-\%m-\%d`
tar -czvf ${BACKUP_DEST}/files.tar.gz ${BACKUP_DEST}
  • 1
    OK, so what's stopping you from doing so? We're a question-and-answer site, and I'm not really seeing a question here. – womble Jul 17 '12 at 22:56
  • I use this command in a cron job. I'd like to have the target .tar.gz file without directories tree and remove the original files used to create the archive. Automatically.. – MultiformeIngegno Jul 17 '12 at 23:08
  • "remove the original files used to create the archive." Huh? – thinice Jul 17 '12 at 23:14
  • In /home/backup/db I have file "a", file "b" and file "c". I use tar to create /home/backup/db/files.tar.gz. When creating the archive I'd like to remove also ORIGINAL "a", "b" and "c". – MultiformeIngegno Jul 17 '12 at 23:18
  • So edit your question to include an actual question. – womble Jul 18 '12 at 0:07

The tar command has a little-known option named --remove-files, which is designed pretty much for this specific use-case. There is a known bug in the interaction between --remove-files and --append, but since you don't appear to be using that, you should be fine.

  • Thanks for the reply. :) For the 1st question I found the -C command.. I tried with: tar -czvf ${BACKUP_DEST}/files.tar.gz ${BACKUP_DEST} -C but a dummy archive is created.. – MultiformeIngegno Jul 18 '12 at 0:33

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.