Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am trying to print a number of files from shell using lpr. I enter something like:

lpr -P PRINTERNAME ./*/dir/file.pdf

but I get "lpr: No file in print request.".

When I use ls as

ls ./*/dir/file.pdf

it correctly lists the files I want to print. Can someone help me understand what is going on?

share|improve this question
    
Does your command work when you specify the path to just one file? –  drs Apr 23 '13 at 21:06
    
yes, it works when I give it a single file. I got around the issue by using a shell script: for x in `ls ./*/dir/file.pdf`; do lpr -P PRINTERNAME $x; done. Still I feel that the wildchars should have worked. –  James Apr 23 '13 at 21:15
    
Sorry, I didn't see that you came up with this workaround before I posted my answer. Either will work... –  drs Apr 23 '13 at 21:52
add comment

2 Answers 2

Without knowing the details of the layout of your directories, I would guess that it's having trouble interpreting the different levels of subdirectories or perhaps spaces in file names.

You can try using find and piping the files to lpr with xargs:

find . -wholename "*/dir/file.pdf" -print0 | xargs -0 lpr -P PRINTERNAME
share|improve this answer
add comment

One of the ways I get the message

lpr: No file in print request.

is when first file by pattern is an empty file.

E.g.:

$ touch f0
$ echo A > f1
$ lpr f*
lpr: No file in print request.

For you for alternative - you do not need ls; actually it is prone for bad errors, e.g. if filenames contain spaces.

As an alternative you could try:

shopt -s nullglob  # So that if there are no matches you won't try to send
                   # pattern to printer.
for x in ./*/dir/file.pdf; do 
     lpr -P PRINTERNAME "$x"; 
done
shopt -u nullglob  # Restore

And remember to QUOTE. Always quote.


Also note:

By using lpr PATTERN all files get queued to one job named as first file in list.

That is:

# List files:
ls file*
file1 file2 file3

# Add to print job
lpr file*

Now file1 file2 and file3 should be in print queue – but not as three jobs, but one. Name of the job is given from the first file if not set by option:

lpq
Rank    Owner   Job     File(s)              Total Size
1st     user    80      file1                9248 bytes
                         |
                         +----- Actually is file1, file2, file3

If you have lp this is reported more verbosely by:

lp file*
request id is PRINTER-362 (3 file(s))

If you want you can also set a name for the job by e.g.:

lpr -T "My 3 Files" file*

lpq
Rank    Owner   Job     File(s)              Total Size
1st     user    80      My 3 Files           9248 bytes
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.