The easiest way to extract the content of compressed files (and compressed archives) is to prepare a script that both recognizes files by type and uses the proper commands for extracting their contents. Almost every compressed file will have an easily recognizable file extension – .Z, .gz, .tgz etc. And, while the commands aren’t very complex, there sure are a lot of them and many options for each.
So, why not attack the problem with a script that saves your precious brain cells for more challenging work? Let’s look at an example that you might want to consider.
In this script, the order in which the file types are listed is important. File extensions like .tar.gz that incorporate simpler file extensions like .gz have to be checked before .gz so that the proper extraction command is used. The case statement, after all, is going to select the first matching criteria that it encounters.
From: Network World