I want tar to pack a complete directory
tar cvjf dir.tbz dir
But make it delete all files
tar cvjf dir.tbz dir --remove-files
However this removes ./dir too. So I tried to cd into directory before packing
tar cvjf dir.tbz --remove-files -C dir .
But that still removes ./dir... what does not make any sense to me, because why should tar delete the working directory itself? Can't I pack a complete directory and remove the files after packing without deleting the whole directory?
I have a process running, that constantly creates files in ./dir and want to pack all files each hour and then remove these that are packed. I could mkdir after tar and delete but that could cause the other process that creates files struggle when it tries to write a new file before mkdir had recreated the directory.
--remove-files
andmkdir
before unlocking and there will be no race conditions.chown
ingdir
to another user, while still giving the process and tar permissions to read/write it via the group or via ACLs. Then, tar will not be able to delete it. The races in the previous comment still apply.