Linux

All posts tagged Linux

GNU Screen is a terminal application for running persistent, multiple sessions inside a single terminal (or in the most useful case, a ssh connection)

Running Screen:

apt-get install screen: installs screen on Debian
screen: starts a new screen session
screen -r: reattaches to an existing screen session
screen -x: reattaches to an existing screen session where the original session is still attached (happens when screen has not been properly detached)
Ctrl-a d: detaches from a running screen session (note this will lose split screen placement – this is the only way I’ve found to avoid that)

Creating and switching between terminal sessions:

Ctrl-a c: Create new terminal session
Ctrl-a n: Switch to next running terminal session (also Ctrl-a space)
Ctrl-a p: Switch to previous running terminal session
exit: This will close the running terminal session, as usual.

Split Screen:

Ctrl-a |: Split screen vertically (note this one isn’t in all screen versions – it is in the Debian one however)
Ctrl-a S: Split screen horizontally
Ctrl-a Tab: Switch to the next screen
Ctrl-a X: Remove active bit of split screen (opposite from | and S)

Copy and Paste:

Screen supports copy and paste between terminal sessions. Copying from a vertically split screen from an ssh session (as in to a different application on your client operating system) can be tricky if it extends over multiple lines, as you’ll get the stuff from the other terminal too – , although I’ve yet to try it.

Ctrl-a [: Starts copy mode. Press enter/space to start, enter/space again to end.
Ctrl-a ]: Paste
Ctrl-a <: Copy from a file
Ctrl-a >: Paste to a file

Other:

Ctrl-a ?: Command reference (also see the manual)

Copy mode can also be used to view the scrollback buffer: after Ctrl-a [ you can use the arrow keys to scroll up to its limits – Esc exits without copying.

On login, bash runs scripts in your home directory depending on a number of factors. Note these scripts don’t seem to require being set executable. A summary, as far as I can make out (tested on Debian lenny):

/etc/profile always seems to be run first

/etc/bash.bashrc will be run next for interactive shells (aka not scripts or su -c)

If the shell has been started with the command /bin/sh, bash emulates the older sh shell and runs the ~/.profile script

A ssh login (and presumably also local login) runs ~/.bash_profile , or if it can’t be found ~/.bash_login or .profile, if they exist (~/.profile being last)

Graphical terminal emulators usually run ~/.bashrc

The command su username from a shell runs ~/.bashrc

The command su -c “command” username from a shell or script doesn’t run any of the scripts (except /etc/profile as always)

The command su -l -c “command” username runs ~/.bash_profile (the -l flag to su emulates a login shell, so the other possibilities mentioned above if .bash_profile doesn’t exist)