Monday, February 26, 2007

Screen Command Usage

Create a new Screen session
screen # creates a default session
screen -S name # creates a session with a name

# Screen has two similar concepts: screens and window sessions.
# screens are seperate processes that show up when doing
# a "screen -ls" listing. Windows are "sub-screens" of a given
# screen process used for split screen modes and such.

Rename an already created window
CTRL-a A # then provide name

Rename a screen (interactively)
CTRL-a :sessionname newsessionname

Rename a screen (without attaching)
screen -X sessionname newsessionname

Detach from a screen session
screen -d # detach from a command prompt
Ctrl-a d # detach from anywhere in the session

List screen sessions

screen -ls

Reattach to a screen session
screen -r # attaches to default session
screen -r name # attaches to specific session (unique string in the name)

Toggle between several attached windows
Ctrl-a Ctrl-a

Attach to an already attached screen (mirror)
screen -x # attaches to default session
screen -x name # attaches to named session

Share a screen session

screen -S name # start and name the screen
Ctrl-a :multiuser on # add multiuser support
Ctrl-a :acladd userids # share the screen to userids (comma sep)

screen -x username/session # attach to the screen (in mirror)

Change permissions on a shared session
Ctrl-a :aclchg userids [permbits] [list]
# permbits = rwx and prefixed by "-" or "+"
# list of commands - #(all windows), ?(all commands)

Remove user access
acldel userids

Lock a Screen
ctrl-a ctrl-x # requires user to enter password to unlock

Copy and Paste from the screen scrollback buffer
Ctrl-a [Esc] # enters scrollback editor (movement like vi)
[spacebar] # starts and stops a copy selection range
Ctrl-a :paste . # pastes the copy buffer to the term

Screenrc options:
/home/> vi .screenrc
#shell -bash
shell -ksh # Make Screenrc exe .profile file on login

# Set the scrollback buffer
defscrollback 5000

# Turn off the startup banner
startup_message off

# displays a status line at the bottom of the terminal window.
hardstatus alwayslastline "Screen: %w %c:%s %D, %M/%d/%Y "

# detach on hangup - if my dial-up session fails, screen will simply
# detach and let me re re-attach later
autodetach on

Split Screen
# Create two screens
screen # create first screen
CTRL-a c # create second screen session (1 screen instance, but 2 window sessions)
CTRL-a S # split the screen
CTRL-a TAB # move to the bottom part of the split
CTRL-a " # will prompt for a screen number. Choose 0 or 1 indicating the window session
CTRL-a Q # quit all splits except the current

Scrollback / Copy and Paste
CTRL-a [ or CTRL-a ESC # frees the cursor to move into scrollback buffer (Copy mode)
# ESC to exit copy mode without copying
# use arrow keys or h,j,k,l to navigate in copy mode
# use CTRL-F and CTRL-B to page up and down in copy mode

ENTER # indicates a start point for text copy
ENTER # (second) indicates an end point for text copy
CTRL-a ] # pastes copied text range

Tuesday, February 20, 2007

SSH Port Forward

Allow port forwarding on the server
# Edit the /etc/ssh/sshd_config
AllowTcpForwarding yes

Local Forward

# create a tunnel to access an ssh server behind a firewall using a gateway
ssh -L 7777: cat -

# access the ssh server via your local machine
ssh -p 7777 localhost

Tuesday, February 13, 2007

Find File Space Usage

Find space used on filesystem level:
du -ks # shows summary of space used on disk in Kb
du -ms # shows summary of space used on disk in Mb
du -gs # show summary of space used on disk in Gb

Find space used on a file level:
find . -type f -ls | awk '{print $7}' | while read size
((TSIZE=TSIZE + $size))
echo "$TSIZE"

Shows largest files in a directory:
ls -l | sort -k 5rn,5 -k 9fd,9
-k = search criteria
5 = sort column five
r = apply reverse sort
n = numeric sort

Shows files using the most space on the filesystem:
du -ak | sort -k 1rn -k 2fd

Shows users using the most space:
# this space list will not include files or dirs that the current
# user has no read permissions on
ls /home/ | while read a
du -sm /home/$a
done 2> /dev/null | sort -k 1n | tail -10