Deleting files after adding to tar archive
Solution 1:
With GNU tar, use the option --remove-files
.
Solution 2:
I had a task - archive files and then remove into OS installed "tar" without GNU-options.
Method:
Use "xargs"
Suppose, we are have a directory with files.
Need move all files, over the week into tar and remove it.
I do one archive (arc.tar) and added files to it. (You can create new archive every try)
Solution:
find ./ -mtime +7 | xargs -I % sh -c 'tar -rf arc.tar % && rm -f %'
Solution 3:
For non GNU tar, you can use "-u" to proccess file per file in a loop
tar -cf archive.tar afile
for myfile in dir/*.ext
do
tar -uf archive.tar $myfile && rm $myfile || echo "error tar -uf archive.tar $myfile"
done