Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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}
share|improve this question
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

1 Answer 1

up vote 3 down vote accepted

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.

share|improve this answer
    
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

 
discard

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.