When you run a program that has a graphical user interface (GUI) from the command line in a terminal window, you cannot enter any other commands in that terminal window until you quit that GUI program. To avoid this, you can add an ampersand (&) to the end of the command that opens the GUI program.
To do this, select Accessories | Terminal from the Applications menu to open a terminal window.
For this example, we will open Gedit. At the prompt, enter the following and press Enter:
$ gedit &
Gedit opens and the command prompt is available again in the terminal window. You can now type another command at the prompt. For example, enter the following at the prompt to open a different editor and press Enter:
$ kate &
To see a list of programs you started using the ampersand (&), type the following command at the prompt:
$ jobs
To close the terminal window, select Close Window from the File menu. You will notice that Gedit and Kate DID NOT stay open. Both programs closed when the terminal window was closed.
There is a command that will prevent GUI programs opened from within a terminal windows from being closed when the terminal window is closed. The nohup command tells the new program you are starting to ignore any future “hangup signals.” For example, this means that Gedit is told to ignore requests to terminate that are sent to it when the terminal window closes.
You can combine the nohup command with the & at the end of the command to start a program. This allows you to open a GUI program from a command line without tying up the command line and the GUI program will not close when the terminal window is closed.
To do this, open another terminal window as described above. Enter the following command and press Enter:
$ nohup gedit &
Gedit opens and will now stay open when the terminal window is closed.
NOTE: Sometimes when you run a program using the & at the end of the command, it may look like you do not get the command prompt back. This happens sometimes when a message is generated when starting a GUI program. The command line is available. You can just type a command, such as pwd (which prints the current working directory to the screen), and press Enter. The command executes and the command prompt comes back.
Close the terminal window this time by typing exit at the command prompt and pressing Enter. This is the same as selecting Close Window from the File menu.
You will notice that Gedit is still open even though the terminal window is closed.
This feature can be useful if you are doing a lot of work in the terminal window and you need access to a GUI program. You don’t have to switch to using the menus on the panel in the middle of typing commands.
by Lori Kaufman