Argh. I searched, wrote the howto to, then searched one more time and found this thread.
No need to start a new post I guess and I don't want to waste the howto. Btw, excellent tips.
My simple, yet semi-thorough, tutorial on using gnu-screen
What is it and what does it do?
Screen is often described as a terminal multiplexer. It can be found on any *nix distro and cygwin even has a port. So what is it useful for?
- It's great if you like to use many command-line applications. If you have to remote connect a lot it's like you can access your desktop from anywhere.
- Gives you the ability to disconnect from a "session", log off the machine, and reconnect later on. This is great when your updating a nix box or running any time consuming command.
- You can customize it's looks and create your own keybindings
- It eliminates the need to have several terminals opened.
- It has an edit mode which is damn useful when reading system logs, lots of output, or other big files.
Examples of screen in action
One of my screen sessions
A split screen session
Putting screen in action
First thing first. Install screen:
Now that it's installed you can simply start a session by typing
"screen" from the command prompt. This sucks though because you are letting screen create it's own names for each session and they can be unusual. I usually start a session like
"screen -S main",
"screen -S update", or name it after whatever commands the session will be executing.
Once you've started you can open a new session inside of screen by typing
"ctrl-a, c". Once your ready to disconnect from the session type
"ctrl-a, d". When you are ready to reconnect type
"screen -r" at the command line or
"screen -x" if the session is already attached and you've ssh'd in and want to connect the that particular session.
Here is a short list of other default keybindings:
- ctrl-a ctrl-a (jumps back and worth between two sessions.)
- ctrl-a shift-s (splits screen)
- ctrl-a shift-x (undo split)
- ctrl-a " (give list of screens)
- ctrl-a spacebar OR n (move to next screen)
- ctrl-a backspace OR p (move to previous space)
- ctrl-a shift-? (help)
Customizing
You can change the way screen looks and behaves by modifying your ~/.screenrc file. One of the first things I do is add some of my own keybindings. Examples:
Code: Select all
bind C screen -t "ncmpc" 0 ncmpc
bind M screen -t "mutt" mutt -y
bind i screen -t "irssi" irssi
bind R screen -t '%{rb} |root' sudo -s -H
bind Q screen -t "qjots" vi ~/.quickjots
bind Y screen -t "yafc" 9 yafc
bind a screen -t "abook" abook
bind t screen -t "torrent"
bind T screen -t "top" sudo top
bind s screen -t 'mysql' mysql -p
bind D screen -t "dict" w3m -cookie www.freedictionary.org
bind E screen -t "encyc" w3m -cookie en.wikipedia.org/wiki/Main_Page
bind N screen -t "note" note
bind P screen -t "lookup" w3m -cookie http://local.google.com/lochp
bind W screen -t "www" w3m -cookie -B
bind V screen -t 'vim' vim
bind L screen cmatrix -f -s -C blue
bind A screen -t 'mixer' alsamixer
bind m screen -t 'metasploit' ~/tools/exploits/framework-2.4/msfconsole
bind v screen -t 'vpn' sudo ~/vpn.sh
Once thing that gets old really quick if you use screen is having to type "ctrl-a n" and "ctrl-a p" to navigate between your screens. I've changed this in my config file by adding a smoother keybinding like "ctrl-
left arrow" and "ctrl-
right arrow. Since the keybinding is often different I'll show you how to do in your configuration file.
- open up in and editor ~/.screenrc. I think this will work with any editor but know it will for sure with vim.
- Now you want to type something similiar to this:
Code: Select all
bindkey "^[Oc" next
bindkey "^[Od" prev
- The thing that might be different is the "^[Od" part. To get the right code you need to press "ctrl-v" then keep holding down the ctrl key and press one of the arrow keys.
Another thing you can do is modify the "hardstatus" in your screenrc file. This is how you can add the tabbed menu at the bottom like in my examples above. Here is what my hardstatus line looks like. To get a grasp on how to change the variables and colors read the man page.
Code: Select all
hardstatus alwayslastline "%{dw} \\\\ %{dB}%50`%{dw} \\---\\\\ %{dB}%-w%-u%50>%{Kw}%n-%t%{dB}%+u%+w%<%> %{dB}\\%=%{dw}\\\\%{dB} Time:%{dw}%C %{dB}%D%{dw} \\"
sorendition = wb
You can also execute commands and use the output in the hardstatus by using "backtick". Add somthing like this in your .screenrc:
Now anywhere in the hardstatus like you put "%50`" the output of the command hostname will magically appear there.
Here is another creative example in how to put your outside weather in screen

.
Add a similiar entry in your crontab:
Code: Select all
*/15 * * * * curl -s http://weather.noaa.gov/weather/current/ABCD.html | grep 'F (' | head -n 1 | awk {print $3 " " $4}' > /tmp/temperature
Create a similiar script:
Code: Select all
#!/bin/sh
while :
do
cat /tmp/temperature
sleep 16m
done
And then add a "backtick" into your screenrc kind of like this:
Now where every you put "%52`" in the "hardstatus line" your current weather will be displayed. example:
Code: Select all
hardstatus alwayslastline "%{dr} %D %C%A %{dd} %{Bw}%-w%{db}%50>%n %t%{dw}%+w%<%>%{dd} %=5%{wB} (%{wr}%52`%{wB})%{wr} %50` "
Well anyhow that's it for my "simple yet semi-thorough" turorial on using screen. It's just one of those command line applications, like vim for example, that the more you play with it the more you see what it can do.