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?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityFrom 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
vs
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.
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.
Solution:
ls *.txt > ouput_file
lp output_file
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.
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??