Aral Balkan

Mastodon icon RSS feed icon

Open from terminal in Linux

On macOS, if you want to open a file in its default viewer/editor from Terminal, you use the open command like this:

open name-of.file

On X-based Linux systems, you can do the same thing using a command called xdg-open. However, it doesn’t really have the same ring to it, does it?

If you want to speak human instead of xdg, add an alias to your shell configuration file (for bash, ~/.bashrc, for zsh, ~/.zshrc). In my case, all I had to do was:

# Add the alias to your shell configuration. 
echo "alias open='xdg-open'" >> ~/.zshrc

# Load your updated configuration.
source ~/.zshrc

And now you can open directories in Files using:

open .

And you can open images in Image Viewer and any other type of file in its default app using open <name of file>.

Enjoy!