Show files in zip linux

View list of files in ZIP archive on Linux

The less utility is capable of peeking into a zip archive. In fact, if you look at the outputs of unzip -l zipfile and less zipfile , you will find them to be identical.

Note, that less zipfile on MacOS-X displays the binary filecontent, so you see a lot of garbage instead of the content of the zip-file. Then you should opt for the «ùnzip -l zipfile«`

@ayaz In what system does less list zipfiles? I see comments telling that it does not work on MAC, Ubuntu, and here I use Debian. Debian also shows binary garbage.

You need the lesspipe helper installed to enable zip file support for less. It’s standard on many linux systems but not on OSX, but you can install it with brew.

It’s a neat hack to use less , but unzip -l seems like the canonical answer, esp. given that it’s a far more universal answer.

Try unzip -l files.zip Or unzip -l files.zip | less if there are too many files to be listed in one page.

Also, See man unzip for more options

@MathiasLykkegaardLorenzen according to man zipinfo : -1 list filenames only, one per line. This option excludes all others; headers, trailers and zipfile comments are never printed. It is intended for use in Unix shell scripts.

for the same. This is a simple and easy to remember one.

You can make the zip appear as a directory (in which you use cd , ls , etc.) by mounting it with the fuse-zip virtual filesystem.

mkdir foo.d fuse-zip foo.zip foo.d ls foo.d cat foo.d/README . fusermount -u foo.d rmdir foo.d 

Another relevant FUSE filesystem is AVFS. It creates a view of your entire directory hierarchy where all archives have an associated directory (same name with # tacked on at the end) that appears to hold the archive content.

mountavfs ls ~/.avfs/$PWD/foo.zip\# cat ~/.avfs/$PWD/foo.zip\#/README . umountavfs 

Many modern file managers (e.g. Nautilus, Dolphin) show archive contents transparently.

AVFS is read-only. Fuse-zip is read-write, but beware that changes are only written to the zip file at unmount time, so don’t start reading the archive expecting it to be modified until fusermount -u returns.

Источник

How to View Contents of ZIP Archive in Linux?

A ZIP archive is a compressed file containing different files that can be sent through email to another user. Users can visualize the content of ZIP files by extracting them from the ZIP Archive in the command line.

Читайте также:  Date options in linux

This article will explain different methods to display the contents of the ZIP archive in Linux.

Method 1: Using the zmore Command

The “zmore” command is pre-installed in the Linux systems. Users can view all the contents of the ZIP archive in Linux:

The output shows that the content “itslinuxfoss” is present in the “myZip1.zip” displayed in the terminal.

Method 2: Using the zcat Command

Similar to the “zmore” command, the “zcat” command can view the Zip file’s contents. But this works on the single zip file only:

The output shows the content of the “myZip1.zip” in the terminal.

Method 3: Using Vim Editor

Vim is a modern text editor with multiple features and tools. To install the vim editor in Linux, execute the below script:

$ sudo apt install vim # Ubuntu, Debian, and LinuxMint $ sudo yum install vim # CentOS $ sudo dnf install vim # Fedora

After the installation of the above script, the vim editor is used to view the contents of the ZIP archive by specifying the name of file “myZip.zip”:

Users can visualize the content of the ZIP archive in the text editor.

Method 4: Using the 7z Archiver

The 7z is another Linux tool used to manage the zip file. To install the “7z Archiver” in the Linux distributions, execute the below script:

$ sudo apt install p7zip-full # Ubuntu, Debian, and LinuxMint $ sudo yum install p7zip # CentOS $ sudo dnf install p7zip # Fedora

To display the contents of the ZIP archive, utilize the “7z” command by specifying the zip file as “myZip.zip” in the below script:

The output unzips the archive file and displays the content of several files.

Method 5: Using the zip and unzip Commands

The last but most important one is the zip and unzip commands. These are used for managing the compressed archives. To use the zip command to view the zip archive’s contents, use the sf options:

Moreover, with the unzip command, you can see the contents of the zipped files as well with the c option:

These all methods are used to view the contents of the ZIP archive in Linux.

Conclusion

To view the contents of the ZIP archive in Linux, “zmore”, “zcat”, “zip, and unzip”, “Vim editors”, and “7z Archiver” are utilized. All these tools have a variety of usages to serve, which are explained in this post with examples..

Читайте также:  Rar архиватор linux mint

Источник

How to get a list of directories in a zip?

I am looking for a way to list the directories in a zip file in bash under Linux. I found out there is an application called zipinfo , which can list the paths in the zip (without any extra noise to have to parse through ( zipinfo -1 foo.zip ), as opposed to unzip -l foo.zip ). However, this isn’t good enough and I am wondering if there is a better way.

4 Answers 4

Archive: foo.zip Length Date Time Name --------- ---------- ----- ---- 0 2015-09-10 20:10 work/ 0 2015-08-31 10:45 work/test1/ 0 2015-08-31 10:50 work/test1/cc/ 0 2015-08-31 10:45 work/test1/dd/ 0 2015-08-31 10:45 work/test1/aa/ 0 2015-08-31 10:45 work/test1/bb/ 0 2015-09-09 21:17 work/tmp/ 0 2015-08-23 18:49 work/tmp/work/ 0 2015-09-08 19:33 work/tmp/work/loop/ 0 2015-08-15 16:00 work/tmp/work/1/ 0 2015-08-15 16:00 work/1/ 0 2015-08-24 18:40 work/dir/ 0 2015-09-05 18:07 work/rename/ --------- ------- 0 13 files
work/ work/test1/ work/test1/cc/ work/test1/dd/ work/test1/aa/ work/test1/bb/ work/tmp/ work/tmp/work/ work/tmp/work/loop/ work/tmp/work/1/ work/1/ work/dir/ work/rename/

I get caution: filename not matched: */ although there are plenty of directories in my zip file. EDIT: Is a zip file expected to contain dedicated directory entries? My file only contains file entries.

Neither unzip -l foo.zip «*/» nor zipinfo -1 foo.zip «*/» are reliable solutions: the Zip file may have been created without dedicated directory entries. For instance the zip tool has the option -D do not add directory entries .

You can try piping unzip -l to awk like this:

All the directories in the unzip -l output end with a slash and $NF prints just the directory path.

On Cygwin

I coudn’t get either of these to work on my Cygwin. For my immediate use, where I only needed to get one directory deep:

zipinfo -1 foo.zip | grep -o "^[^/]\+[/]" | sort -u 

For other directories, you could use xargs in combination with some other parsing thing, something like:

## PSEUDOCODE $ zipinfo -1 foo.zip | \ # from the pipe, run xargs \ # do something like the following while loop, going one file at a time while there is still a '/' in the line; do parse off "[^/]+([/]|)$" from the line print out the new line done | \ sort -u 

System Info

$ uname -a CYGWIN_NT-10.0 C-D-ENG-E-INT3 2.11.2(0.329/5/3) 2018-11-08 14:34 x86_64 Cygwin $ bash --version GNU bash, version 4.4.12(3)-release (x86_64-unknown-cygwin) Copyright (C) 2016 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later This is free software; you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. $ systeminfo | sed -n 's/^OS\ *//p' Name: Microsoft Windows 10 Enterprise Version: 10.0.17134 N/A Build 17134 Manufacturer: Microsoft Corporation Configuration: Member Workstation Build Type: Multiprocessor Free $ 

Источник

Read the contents of a zipped file without extraction?

How can I read the contents of a particular file in an archive without extracting the .zip it is contained within? I’m using the Linux command line. An earlier question asks about viewing the directory of the archive. But for me it is not enough to see just a list of the files in the archive, I need to see the contents of a file in the archive.

Читайте также:  Туннель между двумя linux

@fixer1234 (and others): The linked question asks, “How can I view the files in a ZIP archive?” AFAIC, that’s the same question as “How can I see the contents of a file …?” It’s unfortunate that many of the people who answered that question interpreted it as “How can I view the directory of the archive?” However, Gilles’s answer (naturally) and Rajasekhar Tolety’s answer (apparently) to that question provide answers to this question.

@Scott, maybe we should figure out how to merge the two questions so both topics are covered in one, or refocus the other to clearly be about the directory and then move answers between both places to match the questions. Right now, both are a mishmash.

@fixer1234: I agree, up to a point. The moderators are always telling us that duplicates are a good thing, because they provide a greater surface of exposure to the search engines (i.e., more chances that a search will find one of the questions). But there’s the rub: if a user finds one of the questions, and the linkage isn’t obvious (and nobody looks at the lists of “Linked” and “Related” questions — at least not random followers of search results), then the user has found only a fraction of the answers. DavidPostill cast the final vote to reopen this question; maybe you should talk to him.

@Scott — Given that the question asker marked the “How can I view the directory of the archive?” answer as accepted, I have to think that was likely the intent of the question. It is, unfortunately, ambiguously phrased such that it could mean either interpretation.

8 Answers 8

unzip -l archive.zip lists the contents of a ZIP archive to ensure your file is inside.

Use the -p option to write the contents of named files to stdout (screen) without having to uncompress the entire archive.

unzip -p archive.zip file1.txt | less

For this kind of operation I always pipe the output to less , otherwise the whole file goes flying up the screen before you can read it.

BTW zcat is great for viewing the contents of .gz files without having to uncompress them first.

Edit: Changed this answer to use -p instead of -c . -p extracts the file byte-for-byte, while -c prints the filename and may do EOL conversion. Also, unzip -p lets you extract multiple files, but it does not output in the order given like cat does.

Источник

Оцените статью
Adblock
detector