'Tar' Command '--Remove-Files' Option

If I am trying to archive files in loop using tar command with --remove-files option. If some exception occurs in mid of execution, will the --remove-files option delete the current operating file or retain the original file ?

while read file; 
do
    tar -uf test.tar.gz --remove-files "$file"              
done

1 Answer

As far as my experiments go (and somehow as I expected):

  • the source file is removed only if the command completes normally
  • however, "-u" doesn't remove the previous version of the file, it merely adds it to the end, so repeated updates with the same file will make the TAR file grow indefinitely.
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Marcus Vance

Marcus Vance

Cybersecurity & Digital Privacy Researcher

Marcus Vance is a cybersecurity auditor and technology writer dedicated to educating the public about online safety, data privacy regulations, enterprise security, and emerging cyber threats.

Share this article
Twitter Facebook Pinterest