I am trying to create an alias for redirecting both standard output and standard error of gedit to /dev/null, whilst sending the command to background.

This works:

$ alias gedit='gedit $1 > /dev/null 2>&1'
$ gedit file.txt &

However, adding the background instruction & to the alias string fails to work because it gets immediately interpreted:

$ alias gedit='gedit $1 > /dev/null 2>&1 &'
[1]+  Done                    gedit > /dev/null 2>&1

How should I add this & background instruction to the alias command?

  • Is this for bash? – Timo Jan 17 '14 at 16:45
  • @Timo This would be for use in .bashrc. – Serge Stroobandt Jan 17 '14 at 17:30

I don't think you can do this with an alias, but you can with a function in Bash.

$ gedit() { command gedit "$@" > /dev/null 2>&1 & }


$ gedit file.txt
[1] 24057


The function makes use of Bash's command command. This will invoke the actual executable with a given name, rather than call any aliases or functions that already exist. I opted to use $@ instead which will give you all the command line arguments passed instead of just the first with $1.

  • 1
    I used this to create a general purpose start function, it's basically the same except it accepts any program and its argument: start(){ command $@ &> /dev/null & }, it then can be called like start gedit myFile. – Amr Saber Sep 30 '19 at 11:32

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