How to gunzip without overwriting non-interactively

herder picture herder · Jun 3, 2014 · Viewed 12.1k times · Source

I want to unzip .gz files but without overwriting. When the resulting file exists, gunzip will ask for permission to overwrite, but I want gunzip not to overwrite by default and just abort. I read in a man that -f force overwriting, but I haven't found nothing about skipping it.

gunzip ${file} 

I need something like -n in copying cp -n ${file}

Answer

dogbane picture dogbane · Jun 3, 2014

gunzip will prompt you before overwriting a file. You can use the yes command to automatically send an n string to the gunzip prompt, as shown below:

$ yes n | gunzip file*.gz
gunzip: file already exists;    not overwritten
gunzip: file2 already exists;    not overwritten