10

I want to setup an alias alias open=xdg-open this whould replace the normal linux open command which in turn itself is a symlink to openvt.

I've running a debian wheezy installation with a bash shell. Does Anybody see there possible problems if I do so?

2
  • 2
    I've had it aliased for several years and never had any problems. :-) Sep 8, 2012 at 10:55
  • 2
    For your interest, Debian 11 released with this change: " A new open command is available as a convenience alias to xdg-open (by default) or run-mailcap, managed by the update-alternatives(1) system. It is intended for interactive use at the command line, to open files with their default application, which can be a graphical program when available."
    – Flimm
    Mar 4, 2022 at 7:18

3 Answers 3

10

Yes it is. Once you alias it, it's valid only for your user.

You cold also add it inside ~/.bashrc, so it will be available only for your user and only for the current shell session (aliasing itself again every time you start a new session).

In some distro, .bashrc loads a file called .bash_aliases for every session. You could also add your alias there.

1
  • Be careful not put it in single quotes, as alias open='xdg-open'may result in errors, e.g.: Couldn't get a file descriptor referring to the console while alias open=xdg-open worked for me.
    – math
    Sep 8, 2015 at 6:45
2

alias is simply a text replacement for the original(like preprocessor in C).

It's valid only in the current shell where it was created it unless you add it to .rc file or .profile. Once you exit, the alias is no longer there and as such I don't see why it would cause any problem.

1
  • There's a typo. The file is .profile. I cannot edit it since it's a one letter edit. ;)
    – Zagorax
    Sep 8, 2012 at 13:11
2

On some systems, the open command actually refers to the run-mailcap command. By default, running open is the same as running run-mailcap. Generally, it is safe to override open with a Bash alias, since that only affects the current shell session, and not Bash scripts within that session. Put this in your .bashrc:

alias open='xdg-open'

Debian 11 and related distros (such as Ubuntu 21.10 or later) use the update-alternatives system to manage the open command. So, if you want, you can configure the open command system-wide to refer to xdg-open, like this:

sudo update-alternatives --install /usr/bin/open open /usr/bin/xdg-open 50
sudo update-alternatives --config open

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.