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:

open *.jpg

…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:

#!/bin/bash # open — a better xdg-open if [ $# -eq 0 ]; then echo "Usage: $0 file(s)" exit 1 fi for i in "$@"; do xdg-open "$i" & done

Save it as /usr/bin/open, make it executable with:

sudo chmod +x /usr/bin/open

…and you’re done. Now open *.jpg behaves as you’d expect.


Why This Matters

  1. Predictability – Users coming from macOS expect open to “just work.” Linux shouldn’t be harder for no good reason.

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

  3. Consistency – Since /usr/bin/open is already a symlink to xdg-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.

Popular posts from this blog

Automatically Fix Song Metadata and Filenames on Linux with Beets

throttle traffic on apache

script to show all files with disk usage sizes