Why xdg-open is Irritating by Default (and How to Fix It)
Why xdg-open
is Irritating by Default (and How to Fix It)
If you’ve ever tried to open a batch of files on Linux using xdg-open
, you’ve probably discovered a big irritation: it doesn’t accept shell globs properly.
On macOS, the open
command feels natural. You can run:
…and every JPEG in your folder pops open in your default viewer. Simple, predictable, done.
On Linux, however, xdg-open
— the command that sits behind the /usr/bin/open
symlink on many systems — behaves differently. While it will happily open a single file, it stumbles when you throw a wildcard at it. Rather than expanding the glob and opening each file, it usually just tries (and fails) on the first one, or misinterprets the argument altogether.
That makes it useless in the very situations you’d expect it to shine: folders full of images, PDFs, or text files you want to view in bulk.
The Fix: Replace open
with a Smarter Wrapper
Fortunately, the shell itself can handle globbing. The trick is to insert a thin wrapper script that feeds the expanded argument list into xdg-open
one file at a time.
Here’s a working script:
Save it as /usr/bin/open
, make it executable with:
…and you’re done. Now open *.jpg
behaves as you’d expect.
Why This Matters
-
Predictability – Users coming from macOS expect
open
to “just work.” Linux shouldn’t be harder for no good reason. -
Batch Operations – In real-world use, you often want to check a whole directory of images, PDFs, or spreadsheets.
xdg-open
’s refusal to loop makes this unnecessarily clunky. -
Consistency – Since
/usr/bin/open
is already a symlink toxdg-open
in many distros, replacing it with a wrapper is seamless and doesn’t break anything.
Conclusion
xdg-open
works, but it’s awkward. By default it ignores one of the most basic conveniences of the Unix shell — globbing. Wrapping it in a simple loop transforms it into something useful, making Linux desktop workflows feel much smoother.
Sometimes, the tiniest scripts deliver the biggest usability improvements.