Home Ask Login Register

Developers Planet

Your answer is one click away!

Andrew Parks February 2016

What mechanism allows linux less command to read an encrypted gpg file

After encrypting a file using symmetric encryption, I decided to confirm that the output was encrypted by typing:

gpg -c --force-mdc --s2k-mode 3 --s2k-count 65011712 --output doc.gpg doc.txt

less doc.gpg

To my astonishment, the less command automatically decrypted the contents of doc.gpg and displayed them to me, rather than displaying the raw encrypted contents of the file. This happens only with the "less" command and not with the "cat" command. If "less doc.gpg" is done on a different machine, a command line popup dialog will appear asking for the password.

Could anyone please explain what mechanism is causing gpg to integrate automatically with the "less" command, and what other commands this automatic integration will occur with? Thanks!


larsks February 2016

Start with this:

$ man less

Read a bit, and find:


You may define an "input preprocessor" for less. Before less opens a file, it first gives your input preprocessor a chance to modify the way the contents of the file are displayed...

...To set up an input preprocessor, set the LESSOPEN environment variable to a command line which will invoke your input preprocessor. This command line should include one occurrence of the string "%s", which will be replaced by the filename when the input preprocessor command is invoked.

Post Status

Asked in February 2016
Viewed 2,371 times
Voted 4
Answered 1 times


Leave an answer

Quote of the day: live life