While gzip
does or can store the original name, which you can reveal by running gzip -Nl file.gz
:
$ gzip spark.log
$ mv spark.log.gz spark.log.1.gz
$ gzip -l spark.log.1.gz
compressed uncompressed ratio uncompressed_name
170 292 51.4% spark.log.1
$ gzip -lN spark.log.1.gz
compressed uncompressed ratio uncompressed_name
170 292 51.4% spark.log
gunzip
will not use that for the name of the uncompressed file unless you pass the -N
option and will just use the name of the gzipped file with the .gz
suffix removed.
You may be confusing it with Info-ZIP's zip
command and its related zip
format which is a compressed archive format while gzip is just a compressor like compress
, bzip2
, xz
...
So you just need to call gunzip
without -N
on those files:
gunzip -- */spark.log*.gz
And you'll get spark.log
, spark.log.1
, spark.log.2
... (not spark.log.1.log
which wouldn't make sense, nor spark.1.log
, which could be interpreted as a log file for a spark.1
service as opposed to the most recent rotation of spark.log
).
Having said that, there's hardly ever any reason to want to uncompress log files. Accessing the contents is generally quicker when they are compressed. Modifying the contents is potentially more expensive, but you generally don't modify log files after they've been archived / rotated. You can use zgrep
, vim
, zless
(even less
if configured to do so) to inspect their contents. zcat -f ./*.log*(nOn) | grep...
if using zsh
to send all the logs from older to newer to grep
, etc.
zcat
andzgrep
that can read gzipped files without having to first uncompress them.gunzip
onspark.log.2.gz
would give youspark.log.2
, which is the name of the file that was compressed. I don't quite see why you want to add an extra.log
to the end of that name.