Here I am using debian/testing distribution on my machine but there is something interesting.
# less file.zip "./file.zip" may be a binary file. See it anyway?
Do I need to install some extra packages on my machine in order to be able to open zip files on my machine using less command?
lesspipe tool can transparently convert files to text when you call less on them. This includes decompressing .gz files and listing the contents of .zip files. Debian includes
lesspipe in the
less package but doesn't automatically configure it.
Add the following to your shell's login script (e.g,
This should add two environment variables,
LESSCLOSE. Once you've done this, running
less on a zip file should show you the list of files in the zip file.
Correct answer by satwell on December 16, 2020
unzip -p file.zip | less
I think the ZIP file format first appeared on MSDOS and then MS Windows. It was primarily a way to gather a group of many files together in an archive and compress the combined data. In other words it creates a multi-file compressed archive. You cannot assume a ZIP file contains a single file and assume that file is a text file.
I recall the compression algorithms used by zip utilities changed over the years, though probably later tools could handle earlier compression algorithms. I think the most common tools for creating ZIP files were originally the PKZIP tools created by Phil Katz at PKWare. Later MS WIndows acquired the ability to create ZIP files natively.
On Unix-like systems the traditional equivalent method was to first gather multiple files together using a tool such as tar to create a
something.tar file and then separately
compress it to create a
something.tar.Z file. Later Gnu's
tar acquired compression capabilities from Gnu-Zip (
gzip) and could create a
something.tgz in a single operation.
So a file with a filename extension of
.ZIP is most likely to have originated on Windows not Linux.
If your ZIP file definitely contains a single text file, a general solution would be to pipe the output of an unzip operation into
less. This depends on having an unzip command that reads your particular flavour of zip compression and has options to write to STDOUT.
Commonly installed tools for viewing text files compressed using some "zip" compression algorithm include
bzless. The man pages for these say
GZIP(1) General Commands Manual NAME gzip, gunzip, zcat - compress or expand files SYNOPSIS gzip [ -acdfhklLnNrtvV19 ] [--rsyncable] [-S suffix] [ name ... ] gunzip [ -acfhklLnNrtvV ] [-S suffix] [ name ... ] zcat [ -fhLV ] [ name ... ] DESCRIPTION Gzip reduces the size of the named files using Lempel-Ziv coding (LZ77).
BZMORE(1) General Commands Manual NAME bzmore, bzless - file perusal filter for crt viewing of bzip2 compressed text SYNOPSIS bzmore [ name ... ] bzless [ name ... ]
But this depends on the chosen compression utilities knowing the particular compression algorithm used on your zip file.
Most likely you need an
unzip tool that is compatible with the DOS/Windows ZIP format. On some Linux systems you may need to install this first using whatever package manager is appropriate for your distribution. For example
sudo apt install zip.
$ ls -l eg* -rw-rw-rw- 1 rgb rgb 182 Aug 30 19:10 eg.zip $ unzip -l eg.zip Archive: eg.zip Length Date Time Name --------- ---------- ----- ---- 20 2020-08-30 18:50 eg.txt --------- ------- 20 1 file $ unzip -p eg.zip hello world The end $ unzip -p eg.zip | less hello world The end
Answered by RedGrittyBrick on December 16, 2020
4 Asked on November 16, 2021 by sorayadragon
1 Asked on November 16, 2021 by tubedogg
2 Asked on November 16, 2021 by yaman
0 Asked on November 16, 2021 by chubby-unicorn
1 Asked on November 16, 2021 by gollyjer
1 Asked on November 16, 2021 by jeffrey-g-jarjoura
1 Asked on November 16, 2021 by ahmed-mustafa
0 Asked on November 16, 2021 by veoxer
6 Asked on November 14, 2021
1 Asked on November 14, 2021 by starkers
2 Asked on November 14, 2021 by george-dimitriadis
2 Asked on November 14, 2021
1 Asked on November 14, 2021 by jonesome-reinstate-monica
2 Asked on November 14, 2021 by supermechacow
1 Asked on November 14, 2021 by erik-ovegrd
1 Asked on November 14, 2021 by brunobhr
3 Asked on November 14, 2021 by user1066981
1 Asked on November 14, 2021 by ag1
2 Asked on November 14, 2021 by shooter
Get help from others!