How to avoid creating nohup.out and in this case where the output will be generated?

StackOverflow https://stackoverflow.com/questions/22589993

  •  19-06-2023
  •  | 
  •  

Pregunta

I am running a matlab script which taking input arguments and output folder is assigned in the function. When I am running nohup like this nohup ./matlabscript.h & then it generates a nohup.out file which is really huge. How do I avoid creating that file? The output folder is assigned, so I am not sure whether an output file needs to be assigned? Thank you

¿Fue útil?

Solución

As filmor commented, you could redirect stdout to some file.

nohup ./script > script.out &

or even redirect both stdout and stderr to the same file

nohup ./script > script.out 2>&1 &

or to a different one

nohup ./script > script.out 2> script.err &

To discard an output, redirect it to /dev/null. The data is basically destructed, so no memory is used. See null(4). If you want to discard both outputs use:

nohup ./script > /dev/null 2>&1 &

nohup(1) notices when both outputs are redirected, thus doesn't create the nohup.out file (provided none of the two outputs is a terminal, see isatty(3)).

I would also recommend considering using batch(1) e.g. with a here document

batch << EOJ
  ./script > script.out 2>&1
EOJ

Read the advanced bash scripting guide.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top