Preview files from terminal

With QuickLook you can preview your files without actually opening them. You can do that by selecting a file and pressing the spacebar key.

But you can also call QuickLook from the terminal using the command qlmanage.

Here is the qlmanage command help:


 mteam7 [~] $ qlmanage
Usage: qlmanage [OPTIONS] path...
    -h        Display this help
    -r        Force reloading Generators list
    -r cache    Reset thumbnail disk cache
    -m [name ...]    Display statistics about quicklookd. Stats names:
            * plugins    Show the generators list
            * server    Show quicklookd life information
            * memory    Show quicklookd memory consumption
            * burst        Show statistics about the last burst
            * threads    Show concurrent accesses stats
            * other        Show other information about quicklookd
    -d debugLevel    Integer between 1-4
    -p        Compute previews of the documents
    -t        Compute thumbnails of the documents
    -x        Use quicklookd (remote computation)
    -i        Compute thumbnail in icon mode
    -s size        Size for the thumbnail
    -f factor    Scale factor for the thumbnail
    -F factor    Scale factor for the thumbnail, draw downscaled and compare to 1x
    -z        Display generation performance info (don't display thumbnails)
    -o dir        Output result in dir (don't display thumbnails or previews)
    -c contentType    Force the content type used for the documents
    -g generator    Force the generator to use

The flag we want to use in order to QuickLook is -p. So we can either type the whole thing, like this:


qlmanage -p myfile.txt

Or if you are like me and prefer saving keystrokes, create a function inside the bashrc, like this:


ql () { qlmanage -p "$*" >& /dev/null; }

Then simply call the ql function followed by the filename:


ql myfile.txt
{{ message }}

{{ 'Comments are closed.' | trans }}