gzip files and keep original file

Written by
Date: 2012-12-23 15:20:32 00:00

When you gzip files, the original file is deleted.

If you have file.txt and gzip it with gzip file.txt you will now have file.txt.gz but the original file is not there anymore.

To be able to gzip files and keep the original files untouched you can use this small script.

#!/bin/bash
for i in $@; do
	gzip -c $i > $i.gz
done

That works because you are redirecting the output of gzip to a new file.