There is possibly multiple ways of achieving it, but here are some of essentials:
screen
screen
allows to create virtual console, deattach it from your tty (CTRLA followed by CTRLD) and attach it back (screen -r
) anytime you need.
nohup
nohup
is a software which allows you to run command which will ignore any hangup signal and write output of command to nohup.out
file in cwd
. In practice running following command thought ssh
and then logging out will keep process working nohup dd if=/dev/random of=/dev/null &
.
tee
tee
command in very simple usage works as a fork machine which write it's stdin
to a file and to stdout
simulateously. In your case that would be ls -alh | tee 'ls'
. If you also want to write stderr
to file append 2&>1
(which means "redirect stderr
to stdout
") to your base command.
By combining these solutions you should be able to achieve what you want.
You can also see similar answer: 8703001/1732775.