A small but nice tip. Who doesn’t know it, you want to pack files on the system because they might take up too much space or or or or… Out of habit you use tar with compression on the Linux host or in a script and forget to delete the source file or have to use a separate programm to remove the tar’ed files. I had this “problem” again and again, so i checked whether tar does not support the removal of the source file by default and indeed this is possible with --remove-files usage. A command would look like this:
tar -cvjf my_compressed_file.tar.bz2 --remove-files big_file.log big_file_2.log
The simpler solution is of course to use bz2 instead of tar, bz2 deletes the source file automatically, unless you explicitly specify it.
bz2 --compress source_file.txt
Output:
source_file.txt.bz2
Programs such as xz, gzip and bzip2 are only good for individual files, so otherwise use tar with the correct switch.
