Saturday, May 4, 2024
 Popular · Latest · Hot · Upcoming
51
rated 0 times [  51] [ 0]  / answers: 1 / hits: 54307  / 2 Years ago, sat, december 25, 2021, 4:13:24

On Fedora/Redhat/CentOS the less command seems to magically detect a gzipped file and decompress it on the fly, so you can do:



less my_stuff.csv.gz


I've just noticed this doesn't work on Ubuntu 11



less my_stuff.csv.gz
"my_stuff.csv.gz" may be a binary file. See it anyway?


I've been examining my CentOS VMs to see if there's some shell alias magic that makes it work but there doesn't seem to be. Is gzip support just built in to the CentOS binary?



If anyone knows how this works on CentOS and/or how it can be made to work on Ubuntu I'd be grateful.



I'm aware I can do



zcat my_stuff.csv.gz | less


but that would make my keyboard wear out more quickly.


More From » gzip

 Answers
1

less do not do that by default, but there is a line in the default ~/.bashrc that change the default behavior:



[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"


Be sure to not remove or comment this line.

With this in place, you can page zipped and non-zipped files without knowing, like in



less /var/log/dpkg.log*


where some of the logs can be zipped and some others non-zipped.



For the root account accessed through sudo you cannot do the same thing, but there are two workarounds:




  1. sudo zless file*

  2. sudo -E less file*



In the first case I used zless, that works also for non-zipped file.

In the second one I added the -E option to sudo to preserve your environment variables, to make less work as you would expect.


[#43391] Sunday, December 26, 2021, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
diket

Total Points: 167
Total Questions: 124
Total Answers: 109

Location: Somalia
Member since Wed, Mar 15, 2023
1 Year ago
;