I have a code running on a Linux server. Since it takes hours to run, I have to use nohup
to make sure my code is still running in case I loose my connection to the server. Again since I have to wait hours to see the results, I defined a counter to print out the progress of my code (%). If I loose my connection to the server or close the terminal, the only way that I can see the code is still running is using top
. Is there any way that I can see again the output console (message showing the progress)?
Asked
Active
Viewed 8.7k times
40

MTT
- 5,113
- 7
- 35
- 61
-
4Why not use [GNU screen](http://www.gnu.org/software/screen/) so you can disconnect and reconnect later? – Barmar Feb 05 '15 at 17:50
-
I did not try it! Let me try and I will keep you posted. Thanks. – MTT Feb 05 '15 at 17:53
-
If you have more questions about this, it belongs on superuser.com. It's not a programming question. – Barmar Feb 05 '15 at 17:58
2 Answers
107
You can see the output in real time by running below from another terminal.
tail -f nohup.out

yfpb
- 1,191
- 2
- 7
- 8
-
-
-
4Make sure it is executed in the same directory as nohup command because this command reads the output form nohup.out which is generated in the directory. Awesome. Thanks! – Dami May 06 '20 at 14:32
-
What happens if you delete this file? For any new logs, does it create a new `nohup.out` file? – kaushalpranav Oct 17 '21 at 11:16
-
If you delete it, a new one will be created when `nohup` is run again. Otherwise, `nohup` will just keep appending logs to the existing file. At least that's how it is when I tested. – yfpb Oct 18 '21 at 12:15
34
You can redirect standard output and standard error to a file and look at that file. eg:
nohup command 2>&1 > outputfile &
note default behavior from man page:
If standard output is a terminal, append output to 'nohup.out' if possible, '$HOME/nohup.out' otherwise. If standard error is a terminal, redirect it to standard output
so really you can just run
nohup command &
and then look in nohup.out

Mike Atkins
- 1,561
- 13
- 11