Background a process or program

At times it is useful to see the output of what a program produces by typing its command line name in the terminal (for instance for debugging). At other times typing a program in the terminal just hogs the prompt that could ordinarily be utilized for something else. Launching programs from the terminal can be put in the background easily and I’ve created a bash script to help out.

nohup is used to prevent hangups and then you redirect some the output of the command to /dev/null (the great Linux black hole). Here’s the script:

# Open a command in the terminal in the background.
# Add 'complete -cf bgcmd' to ~/.bashrc for command completion

nohup "$@" &> /dev/null &

Then in the terminal use the bgcmd command with whatever program needed to be put in the background:

bgcmd gedit ~/Documents/recipes.markdown

Backgrounding an already running process

Already running applications can be backgrounded as well. First type Ctrl + z to release the application, then use bg to background it’s output.

Keep in mind that if the terminal or tab is closed the program will close with it; also too the bg command doesn’t suppress all output.