viewing contents of tar/tar.gz/tgz files

Tollef Fog Heen tfheen at raw.no
Mon Oct 18 09:20:50 UTC 2004


* volvoguy 

| I'll admit - I'm no command line whiz, so the answer to my question
| may be embarrasingly simple.
| 
| I'm used to being able to run:
| 
| less somefile.tar.gz
| 
| and have it display the contents of the file.
| 
| When I do this in Ubuntu, I get the message:
| 
| '"somefile.tar.gz" may be a binary file.  See it anyway?'
| 
| So what's different in Ubuntu that it doesn't allow me to do what I've
| been doing for years on other distros?

You need to set LESSOPEN to a filter, like:

: tfheen at yiwaz ~ > echo $LESSOPEN 
|/home/tfheen/bin/lesspipe '%s'
: tfheen at yiwaz ~ > cat ~/bin/lesspipe 
#!/bin/bash

case "$1" in
    *.ps) ps2ascii $1 2> /dev/null;;
    *.tar.gz|*.tgz|*.tar.Z|*.tar.z) tar ztvvf $1 2>/dev/null;;
    *.tar.bz2|*.tbz) tar Itvvf $1 2>/dev/null;;
    *.tar) tar tvvf $1 2>/dev/null;;
    *.gz|*.Z|*.z) gzip -dc $1 2>/dev/null;;
    *.bz2) bzip2 -dc $1 2>/dev/null;;
    *.1|*.2|*.3|*.4|*.5|*.6|*.7|*.8|*.9|*.n|*.man)  FILE=`file -L $1` ; # groff src
    FILE=`echo $FILE | cut -d ' ' -f 2`
    if [ "$FILE" = "troff" ]; then
      groff -s -p -t -e -Tascii -mandoc $1
    fi ;;
esac
: tfheen at yiwaz ~ > 

This allows me to less gzipped files, tar files, man files and so on,
transparently.

-- 
Tollef Fog Heen                                                        ,''`.
UNIX is user friendly, it's just picky about who its friends are      : :' :
                                                                      `. `' 
                                                                        `-  




More information about the ubuntu-users mailing list