How can I open multiple PDF files matching a pattern from the terminal?

0
0
Asked By MellowCedar42 On

I'm organizing a large number of university files whose names follow patterns such as `Subject-Day-Worksheet` and `Subject-Day-Classmaterial`. I know how to use the `*` wildcard for commands like moving files, but I'd like to open all matching PDF worksheets at once. Running `xdg-open Li*` fails with an "unexpected argument" error because the wildcard expands to multiple filenames. Is there a way to make `xdg-open` handle several files, or should I use a different command?

2 Answers

Answered By NimbusTrail58 On

If you want one application to receive all the files at once, call that application directly rather than `xdg-open`. For example, a PDF viewer such as Evince or Zathura may accept multiple filenames, depending on its command-line options. The exact command varies by viewer, while the loop with `xdg-open` uses your normal file associations.

Answered By QuietOrbit7 On

`xdg-open` is generally intended to receive one file or URL at a time, so the shell expands `Li*` into multiple arguments and `xdg-open` rejects the extra ones. Use a loop instead: `for file in Li*; do xdg-open "$file" & done`. The quotes protect filenames containing spaces or special characters, and `&` lets the loop continue opening the remaining files.

CopperVale19 -

You can also add a short delay between iterations if launching everything at once is too much for your desktop: `for file in Li*; do xdg-open "$file" & sleep 1; done`.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.