GNU screen

GNU screen may be a great help.

I guess you must have encountered the following scenarios:

1. You want to work on different directories simultaneously. (So you open multiple terminals and switch between them, using mouse or ctrl + tab which is not very handy.)

2. Need to logoff, but the program that's running should not be terminated. (Use the nohup command. But for interactive programs, this simply doesn't work since you can't interact with the program the next time you login.)

3. Want to search some text or copy text on the terminal but mouse is not available.

GNU screen provides (near) perfect solution for the above scenarios. (And it can do much more.) Simply speaking, GNU screen is the window manager for terminal, analogy to window manager for the X window system.

Now let's have a try. (Of course, you need to first install screen on your system.) Copy the following configuration to ~/.screenrc, start screen.

startup_message off

# use visual bell

vbell off

# replace Ctrl-A by Ctrl-O

#escape ^Oo

# replace Ctrl-A by back tick

escape ``

# set a big scrolling buffer

defscrollback 5000

# open several terminals at startup

screen -t music 5

screen -t software 4

screen -t downlowd 3

screen -t program 2

screen -t admin 1

# Set the caption on the bottom line

caption always '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f %t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %d/%m %{W}%c %{g}]'

The bottom line of the terminal you can see now is the status line of screen. You can see host and date time there.

For scenario 1, working on different directories,

1. Titles 1 to 5 are five different shell sessions you can switch back and forth using the key sequence ` . (The first one is back tick, the one under ESC key, followed by a number key. The default screen command prefix is ctrl + a. I changed it to back tick since this is more familiar for Vim users.)

2. To create a new shell session/window, type `c.

3. To close a shell session/window, just exit the session or type `k.

Next, for scenario 2, you want to logoff and keep the current working status. The following command will do the job.

1. Type `d, which will put screen into detached mode.

2. You can use "screen -ls" to see all your screen sessions on the system, these sessions will not terminate even if you logoff or the remote connection is accidently lost.

3. To restore a screen session, use "screen -r ". If there's only one session, "screen -R" is more convenient.

4. To actually quit a screen, type `:quit .

Finally, scenarios 3, copying text

1. Type ` , which will put screen into copy mode. You can search text in copy mode like in Vim. (/ forwards, ? backwards)

2. Now you can scroll back and forth, move your cursor to the start of the copy location. (Some Vim cursor movement commands are supported.)

3. Type , move to the end of copy location, and type again. The text is then copied.

4. To paste the text, type `].

To make life even better, you can combine the power of your shell with screen. So you can set the title of a window according to you current working directory. Simply put this in your ~/.bashrc. (I use Z shell, which is more powerful than bash, and it can also set the running command as the window title.)

if [ $TERM = "screen" ]; then

PROMPT_COMMAND='MYPWD="${PWD/#$HOME/~}"

[ ${#MYPWD} -gt 20 ] && MYPWD=..${MYPWD:${#MYPWD}-18}

echo -n -e "/033k$MYPWD/033//"

'

fi

Screen can do much more than the simple usages mentioned above, like split window, share session with other user, change terminal encoding. I will refer you to other online articles if you are interested.

GNU Screen Tutorial -- How to use the screen's most important features: http://news.softpedia.com/news/GNU-Screen-Tutorial-44274.shtml

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值