GNU tar --remove-files option

2018-09-28

I just now realized that GNU tar has a --remove-files option. From the man page:

--remove-files
          Remove files from disk after adding them to the archive.

So when creating a tar archive, the option removes each of the original files as soon as it has been added to the archive. I found it especially useful when dealing with a server that is low on disk space.

$ find .
.
./logs
./logs/3.log
./logs/5.log
./logs/2.log
./logs/4.log
./logs/1.log

$ tar --remove-files -czf logs.tar.gz logs

$ ls
logs.tar.gz