Viewing the files contained in a .gz archive using python - python-3.x

I am looking for a simple way to view the contents (file names) of a .gz archive. I saw that there has been a discussion already on how to do this when using .zip archive. So basically I am looking for the analogue of ZipFile.namelist(), but for .gz archives.

.gz files are not, in and of themselves, archives. A .gz file contains a single compressed file. When you decompress foo.bar.gz, you get the file foo.bar. So there's your one name, in the name of the .gz file itself.
You might have a .tar.gz file, which is a TAR (tape archive) file containing a representation of a directory of files, that is then compressed as a single file by gzip. In that case, you would need to use Python's tarfile to read the file and list the contents.

Related

Zipping Directory with Pigz Issue

I am trying to zip a directory with Pigz utilizing it's multi core compression. I'm not necessarily trying to compress, but simply speed up the process of zipping files.
The issue I've come across is that once Pigz is complete, tar archives all files into a single tar inside the zipped file. Is there any way to zip all of these files in the directory, into 1 zip, (each file individually) without having a single tar file?

How to get the list of files (ls command) from bz2 archive?

What is the Unix bash command to get the list of files (like ls) from archive file of type .bz2 (without unzipping the archive)?
First bzip2, gzip, etc compress only one file. So probably you have compressed tar file. To list the files you need command like:
tar tjvf file.bz2
This command uncompress the archive and test the content of tar.
Note that bzip2 compresses each file, and a simple .bz2 file always contains a single file of the same name with the ".bz2" part stripped off. When using bzip2 to compress a file, there is no option to specify a different name, the original name is used and .bz2 appended. So there are no files, only 1 file. If that file is a tar archive, it can contain many files, and the whole contents of the .tar.bz2 file can be listed with "tar tf file.tar.bz2" without unpacking the archive.

Unarchiving .tar files and gunzipping all .gz files for all subdirectories

I have many .tar files which I am unarchiving from an HDD to a server using tar xvf, then I manually go through the directories from the unarchived .tar file and use gunzip *.gz to unzip the .gz files. Is there a way to do all of this with one command using terminal?

Can we add files to a zip archive with modified file names

I want to create a zip archive for some files in folder hierarchy.
for example:
abc.php_0973_890
newone.text_2344_870
I want to have:
abc.phpnewone.txt in my zip archive. Is there any way for doing this?
We can not do that as zip doesnot suuport anything like that, we can use tar for such things as it as options like: --transform which can be used to transform the output filename

Unzip the files and rename with zip file name?

I need to unzip files using 7zip and rename the unzipped files.
Assume that the zip file is 3457.zip and it is contains w.dat and q.doc. I'd like to rename w.dat and q.doc to 3457.dat and 3457.doc.
How can this be achieved using a bat file?

Resources