Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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

I tried to run an example java program using the following command line. However, I do not know what is the trailing part < /dev/null & used for?

java   -cp  /home/weka.jar weka.classifiers.trees.J48 –t train_file  >& log < /dev/null &
share|improve this question
up vote 11 down vote accepted

< /dev/null is used to instantly send EOF to the program, so that it doesn't wait for input (/dev/null, the null device, is a special file that discards all data written to it, but reports that the write operation succeeded, and provides no data to any process that reads from it, yielding EOF immediately). & is a special type of command separator used to background the preceding process.

Without knowing the program being called, I do not directly know why it is required to run it in this way.

share|improve this answer

</dev/null disconnects the program's input from the terminal. Some programs react differently depending on what their standard input is connected to. With the redirection </dev/null, the program can tell that its input is not coming from a terminal, and will receive an end-of-file indication immediately if it tries to read from its standard input.

The lone & at the end causes the program to be executed in the background. This means that you get a shell prompt back immediately. Without the &, you would get a shell prompt back only when the program finishes executing.

Note that the standalone & is unrelated to >&. >& is a redirection operator (in tcsh, bash and zsh) which redirects both the program's standard output and the program's standard error to the file name specified after the operator (here log).

In other words, what the shell does when it sees this command line is:

  • Start a process in the background. In the background process:
    • Connect standard input to /dev/null (the null device).
    • Connect both standard output and standard error to the file called log (creating the file if it doesn't exist yet, and truncating it if it exists).
    • Look for an executable file called java in the $PATH.
    • Execute that file with the 5 arguments -cp, /home/weka.jar, weka.classifiers.trees.J48, –t, train_file`.
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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