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

0
1
Asked By MellowPine47 On

I'm a university student who regularly downloads groups of PDFs named with patterns such as Subject-Day-Classmaterial or Subject-Day-Worksheet. I know I can use wildcards like `Li*` when moving files, but I'm not sure how to use one to open several matching PDFs at once. Running `xdg-open Li*` works for one file but fails when the wildcard expands to multiple filenames, reporting an unexpected argument. Is there a way to make `xdg-open` open all matching files?

3 Answers

Answered By QuietMaple39 On

The dash in the filename probably isn’t the issue. `--` can mark the end of options for some commands, but the main problem here is that the wildcard expands to multiple filenames while `xdg-open` generally handles only one file per invocation.

Answered By BrightCedar61 On

You can also use `find` if you want to restrict the matches to PDFs: `find . -maxdepth 1 -type f -name 'Li*.pdf' -exec xdg-open '{}' ;`. This invokes `xdg-open` separately for each matching file and uses your normal default PDF application.

Answered By CloudyRook8 On

`xdg-open` is intended to receive one file at a time, so the shell expands `Li*` into several arguments and `xdg-open` rejects the extras. Use a shell loop instead: `for file in Li*; do xdg-open "$file" & done`. Quoting the filename protects spaces and special characters; running each command in the background lets the loop continue opening the rest.

SilverKite22 -

If opening everything at once is too much for your system, leave off the `&`, or add a short delay such as `sleep 1` inside the loop.

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.