The first modification I make to .screenrc is to change the escape command. Not unlike many of you, I do not like the default Ctrl-A sequence because of its interference with that fundamental functionality in almost every other context. In my .screenrc file, I add:
escape `e
That's backtick-e.
This enables me to use the backtick as the escape key (e.g. to create a new screen, I press backtick-c, detach is backtick-d, backtick-? is help, backtick-backtick is previous screen, etc.). The only way it interferes (and I had to break myself of the habit) is using backtick on the command line to capture execution output, or pasting anything that contains a backtick. For the former, I've modified my habit by using the BASH $(command) convention. For the latter, I usually just pop open another xterm or detach from screen then paste the content containing the backtick. Finally, if I wish to insert a literal backtick, I simply press backtick-e.
If your friend is in the habit of pressing ^A to get to the beginning of the line in Bash, he/she is in for some surprises, since ^A is the screen command key binding. Usually I end up with a frozen screen, possibly because of some random key I pressed after ^A :-)
In those cases I try
^A s and ^A q block/unblock terminal scrolling
to fix that. To go to the beginning of a line inside screen, the key sequence is ^A a.
^A ^W - window list, where am I
^A ^C - create new window
^A space - next window
^A p - previous window
^A ^A - switch to previous screen (toggle)
^A [0-9] - go to window [0-9]
^A esc - copy mode, which I use for scrollback
I've been using Screen for over 10 years and probably use less than half the features. So it's definitely not necessary to learn all its features right away (and I wouldn't recommend trying). My day-to-day commands are:
^A ^W - window list, where am I
^A ^C - create new window
^A space - next window
^A p - previous window
^A ^A - switch to previous screen (toggle)
^A [0-9] - go to window [0-9]
^A esc - copy mode, which I use for scrollback
I think that's it. I sometimes use the split screen features, but certainly not daily. The other tip is if screen seems to have locked up because you hit some random key combination by accident, do both ^Q and ^A ^Q to try to unlock it.
I couldn't get used to screen until I found a way to set a 'status bar' at the bottom of the screen that shows what 'tab' or 'virtual screen' you're on and which other ones there are. Here is my setup:
#!/bin/sh
# scr - Runs a command in a fresh screen
#
# Get the current directory and the name of command
wd=`pwd`
cmd=$1
shift
# We can tell if we are running inside screen by looking
# for the STY environment variable. If it is not set we
# only need to run the command, but if it is set then
# we need to use screen.
if [ -z "$STY" ]; then
$cmd $*
else
# Screen needs to change directory so that
# relative file names are resolved correctly.
screen -X chdir $wd
# Ask screen to run the command
if [ $cmd == "ssh" ]; then
screen -X screen -t ""${1##*@}"" $cmd $*
else
screen -X screen -t "$cmd $*" $cmd $*
fi
fi
然后设置以下 bash 别名:
vim() {
scr vim $*
}
man() {
scr man $*
}
info() {
scr info $*
}
watch() {
scr watch $*
}
ssh() {
scr ssh $*
}
它会为上述别名打开一个新屏幕,如果使用 ssh,它会使用 ssh 主机名重命名屏幕标题。
I use the following for ssh:
#!/bin/sh
# scr - Runs a command in a fresh screen
#
# Get the current directory and the name of command
wd=`pwd`
cmd=$1
shift
# We can tell if we are running inside screen by looking
# for the STY environment variable. If it is not set we
# only need to run the command, but if it is set then
# we need to use screen.
if [ -z "$STY" ]; then
$cmd $*
else
# Screen needs to change directory so that
# relative file names are resolved correctly.
screen -X chdir $wd
# Ask screen to run the command
if [ $cmd == "ssh" ]; then
screen -X screen -t ""${1##*@}"" $cmd $*
else
screen -X screen -t "$cmd $*" $cmd $*
fi
fi
Then I set the following bash aliases:
vim() {
scr vim $*
}
man() {
scr man $*
}
info() {
scr info $*
}
watch() {
scr watch $*
}
ssh() {
scr ssh $*
}
It opens a new screen for the above aliases and iff using ssh, it renames the screen title with the ssh hostname.
screen -ls # Lists your current screen sessions
screen -S <name> # Creates a new screen session called name
screen -r <name> # Connects to the named screen sessions
使用屏幕时,您只需要几个命令:
^A c Create a new shell
^A [0-9] Switch shell
^A k Kill the current shell
^A d Disconnect from screen
^A ? Show the help
You can remap the escape key from Ctrl + A to be another key of your choice, so if you do use it for something else, e.g. to go to the beginning of the line in bash, you just need to add a line to your ~/.screenrc file. To make it ^b or ^B, use:
escape ^bB
From the command line, use names sessions to keep multiple sessions under control. I use one session per task, each with multiple tabs:
screen -ls # Lists your current screen sessions
screen -S <name> # Creates a new screen session called name
screen -r <name> # Connects to the named screen sessions
When using screen you only need a few commands:
^A c Create a new shell
^A [0-9] Switch shell
^A k Kill the current shell
^A d Disconnect from screen
^A ? Show the help
An excellent quick reference can be found here. It is worth bookmarking.
正在进行一些有趣的工作在 Ubuntu Server 的下一版本中默认情况下会获得良好的 GNU 屏幕设置,其中包括使用屏幕底部显示所有窗口以及其他有用的机器详细信息(例如可用更新数量以及机器是否需要重新启动) )。 您也许可以获取他们的 .screenrc 并根据您的需求进行自定义。
我的 .screenrc 中最有用的命令如下:
shelltitle "$ |bash" # Make screen assign window titles automatically
hardstatus alwayslastline "%w" # Show all window titles at bottom line of term
这样我就始终知道哪些窗口打开了,以及它们当前正在运行什么。
There is some interesting work being done on getting a good GNU screen setup happening by default in the next version of Ubuntu Server, which includes using the bottom of the screen to show all the windows as well as other useful machine details (like number of updates available and whether the machine needs a reboot). You can probably grab their .screenrc and customise it to your needs.
The most useful commands I have in my .screenrc are the following:
shelltitle "$ |bash" # Make screen assign window titles automatically
hardstatus alwayslastline "%w" # Show all window titles at bottom line of term
This way I always know what windows are open, and what is running in them at the moment, too.
Ctrl + A is a great special character for Unix people, but if you're using screen to talk to OpenVMS, then not being able to ^A is going to make you bald prematurely.
In VMS, if you're editing a DCL command prior to execution from the history buffer, Insert mode is off (it has to be for a few reasons I won't get into here) ... to turn it on so you don't over-type your command rather than space things out, you have to hit `^A.
function mkscreen
{
local add=n
if [ "$1" == '-a' ]; then
add=y
shift;
fi
local name=$1;
shift;
local command="$*";
if [ -z "$name" -o -z "$command" ]; then
echo 'Usage: mkscreen [ -a ] name command
-a Add to .bashrc.' 1>&2;
return 1;
fi
if [ $add == y ]; then
echo "mkscreen $name $command" >> $HOME/.bashrc;
fi
alias $name="/usr/bin/screen -d -RR -S $name $command";
return 0;
}
function rmscreen
{
local delete=n
if [ "$1" == '-d' ]; then
delete=y
shift;
fi
local name=$1;
if [ -z "$name" ]; then
echo 'Usage: rmscreen [ -d ] name
-d Delete from .bashrc.' 1>&2;
return 1;
fi
if [ $delete == y ]; then
sed -i -r "/^mkscreen $name .*/d" $HOME/.bashrc;
fi
unalias $name;
return 0;
}
mkscreen perlipc perldoc perlipc
perlipc # Start reading the perldoc, ^A d to detach.
...
# Later, when I'm done reading it, or at least finished
# with the alias, I remove it.
rmscreen perlipc
-a 选项(必须是第一个参数)将屏幕别名附加到 .bashrc (因此它是持久的),而 -d 删除它(这些可能具有破坏性,因此使用风险自担)。 xD
I like to use screen -d -RR to automatically create/attach to a given screen. I created bash functions to make it easier...
function mkscreen
{
local add=n
if [ "$1" == '-a' ]; then
add=y
shift;
fi
local name=$1;
shift;
local command="$*";
if [ -z "$name" -o -z "$command" ]; then
echo 'Usage: mkscreen [ -a ] name command
-a Add to .bashrc.' 1>&2;
return 1;
fi
if [ $add == y ]; then
echo "mkscreen $name $command" >> $HOME/.bashrc;
fi
alias $name="/usr/bin/screen -d -RR -S $name $command";
return 0;
}
function rmscreen
{
local delete=n
if [ "$1" == '-d' ]; then
delete=y
shift;
fi
local name=$1;
if [ -z "$name" ]; then
echo 'Usage: rmscreen [ -d ] name
-d Delete from .bashrc.' 1>&2;
return 1;
fi
if [ $delete == y ]; then
sed -i -r "/^mkscreen $name .*/d" $HOME/.bashrc;
fi
unalias $name;
return 0;
}
They create an alias to /usr/bin/screen -d -RR -S $name $command. For example, I like to use irssi in a screen session, so in my .bashrc (beneath those functions), I have:
mkscreen irc /usr/bin/irssi
Then I can just type irc in a terminal to get into irssi. If the screen 'irc' doesn't exist yet then it is created and /usr/bin/irssi is run from it (which connects automatically, of course). If it's already running then I just reattach to it, forcibly detaching any other instance that is already attached to it. It's quite nice.
Another example is creating temporary screen aliases for perldocs as I come across them:
mkscreen perlipc perldoc perlipc
perlipc # Start reading the perldoc, ^A d to detach.
...
# Later, when I'm done reading it, or at least finished
# with the alias, I remove it.
rmscreen perlipc
The -a option (must be first argument) appends the screen alias to .bashrc (so it's persistent) and -d removes it (these can potentially be destructive, so use at own risk). xD
Append:
Another bash-ism that I find convenient when working a lot with screen:
alias sls='/usr/bin/screen -ls'
That way you can list your screens with a lot fewer keystrokes. I don't know if sls collides with any existing utilities, but it didn't at the time on my system so I went for it.
I like to set up a screen session with descriptive names for the windows. ^a A will let you give a name to the current window and ^a " will give you a list of your windows. When done, detach the screen with ^a d and re-attach with screen -R
到您的 .screenrc 中,如果您 - 像我一样 - 曾经使用分割窗口,因为 Ca S 分割实际窗口,但是 Ca s 冻结它。 所以我只是禁用了冻结快捷方式。
I "must" add this: add
bind s
to your .screenrc, if You - like me - used to use split windows, as C-a S splits the actual window, but C-a s freezes it. So I just disabled the freeze shortcut.
Not really essential not solely related to screen, but enabling 256 colors in my terminal, GNU Screen and Vim improved my screen experience big time (especially since I code in Vim about 8h a day - there are some great eye-friendly colorschemes).
Some tips for those sorta familiar with screen, but who tend to not remember things they read in the man page:
To change the name of a screen window is very easy: ctrl+Ashift+A.
Did you miss the last message from screen? ctrl+actrl+m will show it again for you.
If you want to run something (like tailing a file) and have screen tell you when there's a change, use ctrl+Ashift+m on the target window. Warning: it will let you know if anything changes.
Want to select window 15 directly? Try these in your .screenrc file:
发布评论
评论(18)
我对 .screenrc 所做的第一个修改是更改转义命令。 与你们中的许多人不同,我不喜欢默认的 Ctrl-A 序列,因为它会干扰几乎所有其他上下文中的基本功能。 在我的 .screenrc 文件中,我添加:
escape `e
这是反引号-e。
这使我能够使用反引号作为转义键(例如,要创建一个新屏幕,我按反引号-c,分离是反引号-d,反引号-?是帮助,反引号-反引号是上一个屏幕,等等)。 它干扰的唯一方式(我必须改掉这个习惯)是在命令行上使用反引号来捕获执行输出,或粘贴任何包含反引号的内容。 对于前者,我通过使用 BASH $(command) 约定来改变我的习惯。 对于后者,我通常只是弹出另一个 xterm 或从屏幕上分离,然后粘贴包含反引号的内容。 最后,如果我想插入文字反引号,只需按反引号-e即可。
The first modification I make to .screenrc is to change the escape command. Not unlike many of you, I do not like the default Ctrl-A sequence because of its interference with that fundamental functionality in almost every other context. In my .screenrc file, I add:
escape `e
That's backtick-e.
This enables me to use the backtick as the escape key (e.g. to create a new screen, I press backtick-c, detach is backtick-d, backtick-? is help, backtick-backtick is previous screen, etc.). The only way it interferes (and I had to break myself of the habit) is using backtick on the command line to capture execution output, or pasting anything that contains a backtick. For the former, I've modified my habit by using the BASH $(command) convention. For the latter, I usually just pop open another xterm or detach from screen then paste the content containing the backtick. Finally, if I wish to insert a literal backtick, I simply press backtick-e.
如果您的朋友习惯在 Bash 中按
^A
到达行首,那么他/她会感到一些意外,因为^A
是屏幕命令键绑定。 通常我最终会遇到冻结的屏幕,可能是因为我在^A
之后按下了一些随机键:-)在这些情况下,我尝试
^A s
和^ q
阻止/取消阻止终端滚动来解决这个问题。 要转到屏幕内行的开头,按键序列是
^A a
。If your friend is in the habit of pressing
^A
to get to the beginning of the line in Bash, he/she is in for some surprises, since^A
is the screen command key binding. Usually I end up with a frozen screen, possibly because of some random key I pressed after^A
:-)In those cases I try
^A s
and^A q
block/unblock terminal scrollingto fix that. To go to the beginning of a line inside screen, the key sequence is
^A a
.Ctrl+A? - 显示帮助屏幕!
Ctrl+A ? - show the help screen!
我使用
Screen
已经超过 10 年了,但可能只使用了不到一半的功能。 所以绝对没有必要立即学习它的所有功能(我不建议尝试)。 我的日常命令是:我想就是这样。 我有时会使用分屏功能,但肯定不是每天使用。 另一个提示是,如果屏幕似乎因意外按下某个随机组合键而被锁定,请同时执行
^Q
和^A ^Q
尝试解锁屏幕。I've been using
Screen
for over 10 years and probably use less than half the features. So it's definitely not necessary to learn all its features right away (and I wouldn't recommend trying). My day-to-day commands are:I think that's it. I sometimes use the split screen features, but certainly not daily. The other tip is if screen seems to have locked up because you hit some random key combination by accident, do both
^Q
and^A ^Q
to try to unlock it.我无法习惯屏幕,直到我找到了一种方法,可以在屏幕底部设置一个“状态栏”,显示您所在的“选项卡”或“虚拟屏幕”以及还有哪些其他选项。 这是我的设置:
I couldn't get used to screen until I found a way to set a 'status bar' at the bottom of the screen that shows what 'tab' or 'virtual screen' you're on and which other ones there are. Here is my setup:
我对 ssh 使用以下内容:
然后设置以下 bash 别名:
它会为上述别名打开一个新屏幕,如果使用 ssh,它会使用 ssh 主机名重命名屏幕标题。
I use the following for
ssh
:Then I set the following bash aliases:
It opens a new screen for the above aliases and iff using ssh, it renames the screen title with the ssh hostname.
您可以将 Ctrl + A 中的转义键重新映射为您选择的另一个键,因此,如果您确实将其用于其他用途,例如转到开头bash 中的行,您只需在 ~/.screenrc 文件中添加一行即可。 要使其成为 ^b 或 ^B,请使用:
在命令行中,使用名称会话来控制多个会话。 我每个任务使用一个会话,每个会话有多个选项卡:
使用屏幕时,您只需要几个命令:
可以找到一个很好的快速参考 这里。 值得添加书签。
You can remap the escape key from Ctrl + A to be another key of your choice, so if you do use it for something else, e.g. to go to the beginning of the line in bash, you just need to add a line to your ~/.screenrc file. To make it ^b or ^B, use:
From the command line, use names sessions to keep multiple sessions under control. I use one session per task, each with multiple tabs:
When using screen you only need a few commands:
An excellent quick reference can be found here. It is worth bookmarking.
正在进行一些有趣的工作在 Ubuntu Server 的下一版本中默认情况下会获得良好的 GNU 屏幕设置,其中包括使用屏幕底部显示所有窗口以及其他有用的机器详细信息(例如可用更新数量以及机器是否需要重新启动) )。 您也许可以获取他们的
.screenrc
并根据您的需求进行自定义。我的
.screenrc
中最有用的命令如下:这样我就始终知道哪些窗口打开了,以及它们当前正在运行什么。
There is some interesting work being done on getting a good GNU screen setup happening by default in the next version of Ubuntu Server, which includes using the bottom of the screen to show all the windows as well as other useful machine details (like number of updates available and whether the machine needs a reboot). You can probably grab their
.screenrc
and customise it to your needs.The most useful commands I have in my
.screenrc
are the following:This way I always know what windows are open, and what is running in them at the moment, too.
^AA 切换回您刚刚来自的屏幕。
^A A switches back to the screen you just came from.
Ctrl + A 对于 Unix 用户来说是一个很棒的特殊字符,但是如果您使用屏幕与 OpenVMS,那么无法 ^A 会让你过早秃顶。
在 VMS 中,如果您正在编辑 DCL 命令在从历史缓冲区执行之前,插入模式已关闭(这一定是出于一些我不会进入的原因此处)...要打开它,这样您就不会过度键入命令而不是将内容分开,您必须按“^A”。
Ctrl + A is a great special character for Unix people, but if you're using screen to talk to OpenVMS, then not being able to ^A is going to make you bald prematurely.
In VMS, if you're editing a DCL command prior to execution from the history buffer, Insert mode is off (it has to be for a few reasons I won't get into here) ... to turn it on so you don't over-type your command rather than space things out, you have to hit `^A.
我喜欢使用 screen -d -RR 自动创建/附加到给定的屏幕。 我创建了 bash 函数以使其更容易...
它们创建了
/usr/bin/screen -d -RR -S $name $command
的别名。 例如,我喜欢在屏幕会话中使用 irssi,因此在我的 .bashrc(在这些函数下面)中,我有:然后我只需在终端中输入 irssi 即可进入 irssi。 如果屏幕“irc”尚不存在,则会创建它并从中运行 /usr/bin/irssi(当然,它会自动连接)。 如果它已经在运行,那么我只需重新附加到它,强制分离已附加到它的任何其他实例。 非常好。
另一个例子是为 perldocs 创建临时屏幕别名,因为我遇到了它们:
-a 选项(必须是第一个参数)将屏幕别名附加到 .bashrc (因此它是持久的),而 -d 删除它(这些可能具有破坏性,因此使用风险自担)。 xD
附加:
我发现在大量使用屏幕时很方便的另一种 bash-ism:
这样您可以用更少的击键来列出您的屏幕。 我不知道 sls 是否与任何现有实用程序发生冲突,但当时在我的系统上并没有发生冲突,所以我就选择了它。
I like to use
screen -d -RR
to automatically create/attach to a given screen. I created bash functions to make it easier...They create an alias to
/usr/bin/screen -d -RR -S $name $command
. For example, I like to use irssi in a screen session, so in my .bashrc (beneath those functions), I have:Then I can just type
irc
in a terminal to get into irssi. If the screen 'irc' doesn't exist yet then it is created and /usr/bin/irssi is run from it (which connects automatically, of course). If it's already running then I just reattach to it, forcibly detaching any other instance that is already attached to it. It's quite nice.Another example is creating temporary screen aliases for perldocs as I come across them:
The -a option (must be first argument) appends the screen alias to .bashrc (so it's persistent) and -d removes it (these can potentially be destructive, so use at own risk). xD
Append:
Another bash-ism that I find convenient when working a lot with screen:
That way you can list your screens with a lot fewer keystrokes. I don't know if
sls
collides with any existing utilities, but it didn't at the time on my system so I went for it.我喜欢使用窗口的描述性名称来设置屏幕会话。 ^a A 会让你给当前窗口命名,^a " 会给你一个窗口列表。
完成后,使用 ^ad 分离屏幕并使用 screen -R 重新连接
I like to set up a screen session with descriptive names for the windows. ^a A will let you give a name to the current window and ^a " will give you a list of your windows.
When done, detach the screen with ^a d and re-attach with screen -R
http://www.debian-administration.org/articles/34
我写了一个几年前,但这仍然是一个很好的介绍,得到了很多积极的反馈。
http://www.debian-administration.org/articles/34
I wrote that a couple of years ago, but it is still a good introduction that gets a lot of positive feedback.
我“必须”添加这个:添加
到您的
.screenrc
中,如果您 - 像我一样 - 曾经使用分割窗口,因为Ca S
分割实际窗口,但是Ca s
冻结它。 所以我只是禁用了冻结快捷方式。I "must" add this: add
to your
.screenrc
, if You - like me - used to use split windows, asC-a S
splits the actual window, butC-a s
freezes it. So I just disabled the freeze shortcut.Ctrl+A 是基本命令
Ctrl+A N = 转到***N***下一个屏幕
Ctrl+A P = 转到 ***P***上一个屏幕
Ctrl+A C = ***C***创建新屏幕
Ctrl+A D = ***D***附着你的屏幕
Ctrl+A is the base command
Ctrl+A N = go to the ***N***ext screen
Ctrl+A P = go to the ***P***revious screen
Ctrl+A C = ***C***reate new screen
Ctrl+A D = ***D***etach your screen
并不是真正重要,不仅与屏幕有关,而且 在我的终端、GNU Screen 和 Vim 中启用 256 色 极大地改善了我的屏幕体验(特别是因为我每天在 Vim 中编码大约 8 小时 - 有一些很棒的护眼配色方案)。
Not really essential not solely related to screen, but enabling 256 colors in my terminal, GNU Screen and Vim improved my screen experience big time (especially since I code in Vim about 8h a day - there are some great eye-friendly colorschemes).
Ctrl+a 是一个特殊键。
Ctrl+a d - [d]etach,将程序(irssi?)留在后台,回家。
Ctrl+a c [c]创建一个新窗口
Ctrl+a 0-9 按数字在窗口之间切换
screen -r - 返回分离会话
涵盖 90% 的用例。 不要尝试一次显示所有功能。
Ctrl+a is a special key.
Ctrl+a d - [d]etach, leave programs (irssi?) in background, go home.
Ctrl+a c [c]reate a new window
Ctrl+a 0-9 switch between windows by number
screen -r - get back to detached session
That covers 90% of use cases. Do not try to show all the functionality at the single time.
对于那些熟悉 screen 但往往不记得在手册页中读过的内容的人来说,有一些提示:
.screenrc
文件中尝试这些:这将为 Windows 10 到 19 分配 ctrl+a shift+0 到 9。
Some tips for those sorta familiar with screen, but who tend to not remember things they read in the man page:
.screenrc
file:That assigns ctrl+a shift+0 through 9 for windows 10 through 19.