Run a command in a shell and keep running the command when you close the session

screen! It’s the best thing since sliced bread. (Yeah, I know others have already suggested it, but it’s so good the whole world should join in and suggest it too.)

screen is like, like, ummmm … like using VNC or the like to connect to a GUI destop, but for command shell windows. You can have several shell “windows” open at once in the same screen session. You can do stuff like:

  1. Start a screens session using “screen -dR” (get used to using -dR)
    • run some commands in one window
    • press CTRLA,C to create a new window open a file there in vim
    • press CTRLA,0 to go back to the first window and issue some command on the file you just edited
    • CTRLA, 1 to go back to your vim session
    • CTRLA, C for yet another window and maybe do “sudo – su” (because you just happen to need a full root shell)
    • CTRLA, 0 and start a background process
    • CTRLA, C to create yet a new window, “tail -f” the log for that background process
    • CTRLA, d to disconnect your screen then CTRLD to disconnect from the server
    • Go on vacation for three weeks
    • Log on to the server again and issue “screen -dR” to connect to your existing screen session
    • check the log in the the fourth window with CTRLA, 3 (it’s like you’ve been there watching it all the time)
    • CTRLA, 1 to pick up that vim session again
    • I guess you’re starting to get the picture now? =)

It’s like magic. I’ve been using screen for longer than I can remember and I’m still totally amazed with how bloody great it is.

EDIT: Just want to mention there’s now also tmux. Very much like screen, but has some unique features, splitting the windows being the most prominent one.

Leave a Comment

tech