nohup for running a command on a remote server in background, and use
nohup.out file to check the progress. Can I set the
nohup to re-write
nohup.out as it only contains one line (the last stdout)?
There's no option for what you ask in either external
nohup and or shell-specific implementation. Couple of alternative ideas:
Truncate the file with redirection. Something like:
nohup firefox 2>&1 > nohup.out &. Same thing are usually, but just done manually.
rmfile before starting new command. Something like:
rm nohup.out; nohup firefox 2>&1 &
From comments, it seems as if the user wants to be able to check the output file and then empty it before checking again.
To do this, start the program with a
>> redirection to the output file:
$ somecommand >>logfile &
logfile in whatever manner you want. When you want to empty the file, simply do
This would truncate the file but leave it in place. When the program next writes to the output file, it will write to the start of the file.
>> to open the file in "append mode". This means that any new writes into the file will always happen at the (current) end of the file.
Had we used
> and then truncated the file, new writes in the file would have happened at the point in the file where they would originally had been placed. This means that the region between the start of the file and the new contents would have been filled with nul-bytes.