Screen Is Such A Beautiful Command

April 19, 2006 – 8:51 am

I know I am very late to this party, but is screen one of the most beautiful GNU/Linux commands or what? I am in the process of fixing some file server issues in the lab, and part of this process involves copying large amounts of data back and forth (on the order of hundreds of gigabytes) across the network. I use rsync to do the copying, another beautiful command.

The problem I would have with all of this copying, though, is that sometimes I would get an error, or sometimes I wouldn’t set the rsync flags correctly and wouldn’t realize it until the next day when not everything was copied the way I wanted it to be. I then adjusted my schedule so that I could stop by the lab every few hours on the weekend, and I would come back in late in the evening on weekdays before I went to bed to check on things.

One of the guys in the building told me about screen, which allows me to run a command on a new screen, detach this screen, and then pick this screen up to look at it from another computer. For example, before running rsync locally on our file server, I would issue the command screen on this server, and then rsync with the proper flags. I could then hit (and hold down) Ctrl-a-d to detach the screen. I then went home, ssh‘ed back into the file server, and issued the screen -r command. Presto! I was looking at the same terminal in which I executed the rsync command and could see all of the output as though I was still sitting right there at the file server.

I haven’t verified this, but I imagine that screen only works when you are still logged in to the computer on which you originally issued this command. For example, if I sat down at the file server, typed screen, then the appropriate formulation of rsync and then logged out, I don’t think I would be able to pick up this screen when I ssh‘ed in. It would die when I logged out of the file server.

But what a wonderful command screen is. One of the copy processes finished at 11:00pm last night, so from my iBook at home I was able to check its progress as it approached completion and start a new rsync before I went to bed. There are a whole bunch of little reasons that I really like Linux, and screen has just been added to this list.

  1. 3 Responses to “Screen Is Such A Beautiful Command”

  2. Never used screen. Sounds slick. I know you said you hadn’t tested it, but perhaps using nohup allows you to log off from the server.

    By mda on Apr 19, 2006 at 9:50 am

  3. Yup, I think that’s right. I would imagine nohup screen would allow me to pick the screen up via ssh.

    Usually these screens are killed when you log out, so I would imagine I would have to manually kill the screen I created with nohup.

    By jjk on Apr 19, 2006 at 9:52 am

  4. Here’s what I just tried from an X terminal:

    $ screen man screen
    ^A d
    Log out
    Log back in and open up a new X terminal
    $ screen -r

    There I was back at the man page. No nohup needed. I didn’t dig around the man page enough to see what the limitations were.

    By mda on Apr 19, 2006 at 10:30 am

Post a Comment