ls *.txt | lp

I was told that this command above wouldn't do anything but start an empty print queue

if so then wouldn't the command

cat *.txt | lp

print all files that end in .txt right?

2 Answers 2


From the lp manpage.

DESCRIPTION lp submits files for printing or alters a pending job. Use a filename of "-" to force printing from the standard input.

So depending on your print system you might get different results from

lp *.txt


cat *.txt | lp -

The former lp looks at each file individually (and knows the name for it). In the latter the output of all those files is made into one and then lp treats it as one unnamed file.

Some print systems do a cover page per thing submitted - so you can see how it might be different with "N" things vs 1.

  • i agree with this, i think ls *.txt | lp lists and prints the files one by one and cat *.txt | lp prints all the files as one unnamed file
    – OneEyedOwl
    Apr 27, 2021 at 16:21

ls *.txt and cat *.txt is not the same at all.

ls *.txt will list all the files in the current directory with the extension ".txt".

while cat *.txt try to find a file "*.txt" from the current directory and print the file content on standard output.


ls *.txt > ouput_file
lp output_file
  • so ls *.txt | lp would try to list all files that end in .txt and print them while cat *.txt | lp would look for a file named ".txt" from current directory and try to print it
    – OneEyedOwl
    Apr 27, 2021 at 15:22
  • @OneEyedOwl ls *.txt | lp will print, one file per line all filename ending in txt, while cat *.txt|lp will print all file content in alphabetical order.
    – Archemar
    Apr 27, 2021 at 15:40
  • Hi @OneEyedOwl - ls *.txt is giving output matching the names of the files (i.e. think of it as a file with the names of all the files in it). The man page for lp on my machine doesn't mention that supplying a list of names on stdin will print each of them - perhaps yours does??
    – Mr R
    Apr 27, 2021 at 23:04
  • @Archemar why you marked my answer "-1"??
    – Vipul Jain
    Apr 28, 2021 at 12:05
  • Someone give you a "-1" but I didn't, I just review you post in review queue and add the comment above.
    – Archemar
    Apr 28, 2021 at 13:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .