when starts session named any name like this screen -S name1
i want to open tabs windows in this screen session like when open tabs in gnome-terminal like this
gnome-terminal --tab -e "some commands"
so how to do this ?
when starts session named any name like this screen -S name1
i want to open tabs windows in this screen session like when open tabs in gnome-terminal like this
gnome-terminal --tab -e "some commands"
so how to do this ?
You're looking for this to add to your .screenrc file:
screen -t tab1
screen -t tab2
Here's a nice basic .screenrc to get you started with a status bar etc. NOTE: This is typically located in your home directory /home/<username>/.screenrc
.
screen -t validate #rtorrent
screen -t compile #irssi
screen -t bash3
screen -t bash4
screen -t bash5
altscreen on
term screen-256color
bind ',' prev
bind '.' next
#
#change the hardstatus settings to give an window list at the bottom of the
#screen, with the time and date and with the current window highlighted
hardstatus alwayslastline
#hardstatus string '%{= kG}%-Lw%{= kW}%50> %n%f* %t%{= kG}%+Lw%< %{= kG}%-=%c:%s%{-}'
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %m-%d %{W}%c %{g}]'
The example .screenrc
below will create 2 tabs and run 3 echo commands in each.
screen -t tab1
select 0
stuff "echo 'tab1 cmd1'; echo 'tab1 cmd2'; echo 'tab1 cmd3'^M"
screen -t tab2
select 1
stuff "echo 'tab2 cmd1'; echo 'tab2 cmd2'; echo 'tab2 cmd3'^M"
altscreen on
term screen-256color
bind ',' prev
bind '.' next
#
#change the hardstatus settings to give an window list at the bottom of the
#screen, with the time and date and with the current window highlighted
hardstatus alwayslastline
#hardstatus string '%{= kG}%-Lw%{= kW}%50> %n%f* %t%{= kG}%+Lw%< %{= kG}%-=%c:%s%{-}'
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %m-%d %{W}%c %{g}]'
This technique makes use of screen's select
and stuff
commands to initially select one of the tabs, and then "stuff" a string into it.
.screenrc
fileIf you're looking for the scenario where you can:
.screenrc
fileThen this is the one for you! Be prepared though. This one can get a little tricky with the command lines.
For starters let's create a screen session:
$ screen -AdmS myshell -t tab0 bash
The switches -AdmS
do the following:
(See the screen man page for more details)
-A
Adapt the sizes of all windows to the size of the current terminal. By default, screen tries to restore its old window sizes when attaching to resizable terminals
-d -m
Start screen in "detached" mode. This creates a new session but doesn't attach to it. This is useful for system startup scripts.
-S sessionname
When creating a new session, this option can be used to specify a meaningful name for the session. This name identifies the session for "screen -list" and "screen -r" actions. It substitutes the default [tty.host] suffix.
Now let's start loading it up with tabs + their commands:
$ screen -S myshell -X screen -t tab1 vim
$ screen -S myshell -X screen -t tab2 ping www.google.com
$ screen -S myshell -X screen -t tab3 bash
These 3 commands will create 3 additional tabs and run vim, ping google, and launch a bash shell. If we list out the screen sessions we'll see the following:
$ screen -ls
There is a screen on:
26642.myshell (Detached)
1 Socket in /var/run/screen/S-root.
If we connect to the screen session, myshell, and list the tabs that it contains we'll see the following:
$ screen -r myshell
Hit this key combination: Ctrl+A followed by Shift+"
Num Name Flags
0 tab0 $
1 tab1 $
2 tab2 $
3 tab3 $
Switching to tab2:
64 bytes from ord08s08-in-f20.1e100.net (74.125.225.116): icmp_seq=443 ttl=55 time=41.4 ms
64 bytes from ord08s08-in-f20.1e100.net (74.125.225.116): icmp_seq=444 ttl=55 time=33.0 ms
64 bytes from ord08s08-in-f20.1e100.net (74.125.225.116): icmp_seq=445 ttl=55 time=30.1 ms
The above commands are the basic way to accomplish what the OP was looking for. This of course can be condensed and refined using Bash aliases or even shell scripts, this is merely to demonstrate the capability and show the way!
screen "cd /foo/bar/; summon_cthulhu;" <<-- in that screen session
– Runium
May 05 '13 at 20:02
Last login on ... Welcome to XXX, N new mails....
. At least that is how I read the heading of the Q.
– Runium
May 05 '13 at 20:48
man
followed by the name of the tool, so you'd type man screen
. It will tell you what the switches do if you search through it. I've linked to a web version of screen's man page in my answer as well.
– slm
May 06 '13 at 10:35
-D
is a power detach, so if you run the command screen -DmS blah
you'll notice that it doesn't detach from the terminal. If you screen -r blah
into it and type exit in the shell, it will then close. The -d
on the other hand will detach when you run screen -dmS blah
. You have to be careful with the terminology. If I understand you correctly, yes, with a -d
, if you disconnect from it (Ctrl+A d), everything inside will remain and you can reconnect. Does that help? If you have questions about screen you can ask those as separate questions.
– slm
May 07 '13 at 11:07
a small addition to the answer. stuff is first echoing the command, then it's putting it on the command line, and then executes it if the \n or ^M ends the line.
since the echo annoyed me, i've chained \nclear\n as the last command, so the screen window starts clean.
screen -S name1 --tab -e "some commands"
i hope u get what i am asking about ? – Ahmed Zain El Dein May 05 '13 at 21:25gnome-terminal --tab -e "commands " --tab -e " commands
this will open one window of terminal with two tabs for instance i mean :) thank u – Ahmed Zain El Dein May 05 '13 at 21:39