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
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.
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.
`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.

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.