I am looking at how to print a file over ssh. Two websites (The Linux Documentation Project and Computer Hope) suggest the command "lpr" but both seem to suggest two different methods, with no obvious reason why they are different or which should be used in different circumstances.

Option 1:

lpr <filename>

Option 2:

cat <filename> | lpr

I understand that option 1 simply prints the file, whereas option 2 uses cat to read the file and pipes it to lpr which then prints it, but why is that useful? In what cases should I use one or the other or are they totally equivalent? (If so, surely option 1 is better as it takes less typing...)

  • you can use either method, maybe they did an example where it shows you can also pipe something to the printer. if i know 'cat file.txt | lpr' works other things work too. for example 'tail -n 10 /var/log/syslog | lpr' – Frank Schrijver May 18 '16 at 15:25
  • I realise the second method could be used with other commands, but why would you ever use cat and pipe? Surely doing that is totally redundant? – FJC May 18 '16 at 17:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.