How to prevent the gio open command from outputting texting in the console?

ph flag

I use the gio open command very often, so what I have done is I added an alias for it in the .bashrc file

alias open="gio open"

Hence, I can simply write open . or open ~/Pictures/example.png as an example.

However, I can't prevent the annoying output of gio because it doesn't have a --quite option by default, gio open outputs some messages during its job, for example:

msi@msi:~/Pictures$ open image-3.jpg 
(gthumb:37944): Gtk-WARNING **: 08:00:54.815: Failed to register client: GDBus.Error:org.gnome.SessionManager.AlreadyRegistered: Unable to register client

So what I have found is that some people were using the redirect operator to redirect the output of a command from the standard output (the shell) to /dev/null since everything gets written to this 'device' gets deleted automatically directly.

Could you help with this?

cn flag

Suppressing error output

Warning messages of applications, in your example "gthumb", are not send to standard output, but to stderr. You can suppress these messages like:

gio open image-3.jpg 2>/dev/null

An alias as

alias open='gio open 2>/dev/null'

will work to automate also that aspect in your alias.

Supressing all output

To eliminate all output, redirect both file descriptor 1 (stdout) and 2 (stderr) to /dev/null:

gio open image-3.jpg 1>/dev/null 2>/dev/null

Following has the same effect, but allows you to specify the final target only once:

gio open image-3.jpg >/dev/null 2>&1

stdout is redirected to /dev/null, and stderr to stdout, which became /dev/null. 1 can be omitted because it is the default output.

Bash and other shells also allow this shortcut notation:

gio open image-3.jpg &>/dev/null
Normal avatar
ph flag
Thanks, what does the number 2 indicate? errors? are there other numbers?
vanadium avatar
cn flag
2> means stderr

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.