Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

Suppose that I want to run a Java program so I would type

java myProgram

and then suppose that it prints some output to the screen but takes a few hours to finish running. If I want to keep working on the same terminal while it runs, what is the command that I should use? I tried & at the end and it did not seem to work.

share|improve this question

marked as duplicate by Florian Diesch, i08in, Warren Hill, Sylvain Pineau, karel Jun 13 '14 at 8:00

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

up vote 2 down vote accepted

Just add a & after the command. This will make the command run on the background.

Notice that you will still get the output of it, so you may want to redirect the output to /dev/null or to some configuration file.

E.g. in order to redirect both stdout and stderr:

java myProgram > /dev/null 2>&1 &
share|improve this answer

Since the program runs a long time, you may want to consider using screen. You can run the program and then start another command prompt with Control-a Control-c. You can do that as many times as you want, and be working on several things at once. Also, even if you log out and then back in later (just don't shut down), you can reconnect to screen and see how it's doing. Do "man screen" for info.

There is also tmux, which is a similar tool, but you'll need to install it.

share|improve this answer

I think screen will best answer your specific question, but it sounds like your workflow would benefit the most from using tabs.

To open a new tab in terminal, with the terminal selected you press Ctrl+T, and you can switch between tabs by pressing Ctrl+PgUp or Ctrl+PgDown to switch between them.

This quickly becomes intuitive, and ends up being efficient as you can quickly switch between tabs to check on long running programs, or quickly spawn more tabs as you busy the ones you're working in with long tasks.

share|improve this answer

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