初探screen

screen的用法

1> screen -h
Use: screen [-opts] [cmd [args]]
 or: screen -r [host.tty]

Options:
-4            Resolve hostnames only to IPv4 addresses.
-6            Resolve hostnames only to IPv6 addresses.
-a            Force all capabilities into each window's termcap.
-A -[r|R]     Adapt all windows to the new display width & height.
-c file       Read configuration file instead of '.screenrc'.
-d (-r)       Detach the elsewhere running screen (and reattach here).
-dmS name     Start as daemon: Screen session in detached mode.
-D (-r)       Detach and logout remote (and reattach here).
-D -RR        Do whatever is needed to get a screen session.
-e xy         Change command characters.
-f            Flow control on, -fn = off, -fa = auto.
-h lines      Set the size of the scrollback history buffer.
-i            Interrupt output sooner when flow control is on.
-l            Login mode on (update /var/run/utmp), -ln = off.
-ls [match]   or
-list         Do nothing, just list our SockDir [on possible matches].
-L            Turn on output logging.
-m            ignore $STY variable, do create a new screen session.
-O            Choose optimal output rather than exact vt100 emulation.
-p window     Preselect the named window if it exists.
-q            Quiet startup. Exits with non-zero return code if unsuccessful.
-Q            Commands will send the response to the stdout of the querying process.
-r [session]  Reattach to a detached screen process.
-R            Reattach if possible, otherwise start a new session.
-s shell      Shell to execute rather than $SHELL.
-S sockname   Name this session <pid>.sockname instead of <pid>.<tty>.<host>.
-t title      Set title. (window's name).
-T term       Use term as $TERM for windows, rather than "screen".
-U            Tell screen to use UTF-8 encoding.
-v            Print "Screen version 4.01.00devel (GNU) 2-May-06".
-wipe [match] Do nothing, just clean up SockDir [on possible matches].
-x            Attach to a not detached screen. (Multi display mode).
-X            Execute <cmd> as a screen command in the specified session.

我一般使用screen -S readableName给screen session指定一个名字,从而在时间过去很久之后,看到这个名字还能想起来,它里面还在跑什么程序。

detach的方法,可以有3中,一种直接关掉窗口,一种是ctl+a d(前提是仍然使用它的默认行为),一种是在另外的窗口中,使用screen -d session的名字。


当进入一个screen之后,如何显示而且简单地显示出,我们正在所在的screen的名字呢?

每个screen都有一个私有的变量STY,该变量的值就是pid.screen的名字

0> screen -ls
There is a screen on:
	2030.huau	(Detached)
1 Socket in /var/run/screen/S-zhishan.

zhishan@fedora.heisenbug-20.mr.com: ~ 
1> screen -r huau
然后echo $STY输出结果就是2030.huau


因此,可以配置到PS1变量中:

if [ "x$STY" != "x" ]; then
export PS1='$STY@\H: $PWD'"
> "
else
export PS1="\u@\H: \w 
\$?> "
fi

注意,这个文件需要配置自己用户下的.bash_profile(如果你的$SHELL是bash的话)



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值