keep a command running after logout
Start a long job so it survives closing the terminal or the ssh session, and come back to it.
Steps
-
nohup long-command > out.log 2>&1 &start it in the background, immune to the hang-up
-
tmux new -s workor start it inside a tmux session; Ctrl+B then D leaves it running
-
tmux attach -t workcome back to it later, even from another ssh login
-
screen -S workthe same with screen; Ctrl+A then D leaves it
-
screen -r workcome back to the screen session
-
disown -h %1already running? Ctrl+Z, then bg, then this, and it survives logout
Commands used
nohuptmuxscreendisown
Each has a page in lore: lore nohup opens it.
Related recipes
- list and close tmux or screen sessionsSee the terminal sessions left running, join one, or end them.
- add a folder to the pathLet the shell find programs in a folder, for good, and reload the settings without logging out.
- add to the end of a fileAdd lines to a file without replacing it, also to a file only root can write.
- argument list too long"Argument list too long" from rm, cp or mv: too many files for one command line. Hand them over in batches.