Can GNU tar add many files to an archive, deleting each one as it is added?
This is useful when there is not enough disk space to hold both the entire tar archive and the original files - and therefore it is not possible to simply manually delete the files after creating an archive in the usual way.
Changing How tar Writes Files. Normally, tar writes extracted files into the file system without regard to the files already on the system--files with the same name as archive members are overwritten.
1) How to remove a single file from tar file To test the files in a tar file you can use “-t” switch with tar command. We can use the “–delete” switch with tar command to remove files from already created tar file.
In the Archive Delete window, expand the directory tree by clicking the plus sign (+) or folder icon next to the object you want to expand. Objects on the tree are grouped by archive package description. Select the archived objects that you want to delete. Click Delete.
The simplest way to add a file to an already existing archive is the ' --append ' (' -r ') operation, which writes specified files into the archive whether or not they are already among the archived files. When you use ' --append ', you must specify file name arguments, as there is no default.
With GNU tar, use the option --remove-files
.
I had a task - archive files and then remove into OS installed "tar" without GNU-options.
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)
find ./ -mtime +7 | xargs -I % sh -c 'tar -rf arc.tar % && rm -f %'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With