User Tools

Site Tools


shell

This is an old revision of the document!


Shell tips

Environment Modules

The environment modules package can be used to dynamically configure your shell environment for different software packages. If you have two versions of the R statistics package you could easily switch between the two using the module command:

$ type -a R
R is /usr/bin/R
$ module load R/2.11.0
$ type -a R
R is /paracel/paracel/biosoft/R/2.11.0/bin/R
R is /usr/bin/R

Searching for a string in multiple files

Ever need to search through all your files for a certain word or phrase? You probably know about the grep command, but did you know it's recursive?

Here's an example. In this case we're searching for the word "modules":

grep -r "modules" .

By using the "-r" switch, we're telling grep to scan files in the current directory and all sub-directories. It will return a list of files the string was found in, and a copy of the line it was found on.

If you'd rather just get the file names and skip the rest of the output, use the "-l" switch, like so:

grep -lr "modules" .

Here's another tip: grep also supports regular expressions, so matching against a wildcard pattern is easy:

grep -lr "mod.*" .

That command will print a list of files containing any word starting with "mod".

You can also use grep to search for multiple words:

grep -r "drupal\|joomla\|wordpress" .

And, of course, grep supports file name wildcards in the standard unix fashion. In this example, grep will search only file names starting with "log":

grep -lr "mod.*" ./log*

GNU screen tips

GNU screen is a terminal multiplexer. That means you can run multiple terminals inside one terminal. It has other advanced features like detaching/reattaching, which comes in handy when you use a poor network link and you have important jobs running on the remote end.

Basic usage

  • Start screen by typing screen in a new shell window.
  • To get help, just use “Ctrl-A” then “?”.
  • Create a new window: C-a c (Control-a c)
  • Switch to the previous window: C-a p
  • Switch to the next window: C-a n
  • Alternate between two windows: C-a a
  • Switch to a window by number: C-a 1 or C-a 2, etc.
  • List active screen's: screen -ls
  • Re-attach to screen: screen -x or screen -r session_name
  • Detach from the window using Ctrl-A d. This will drop you into your shell. All screen windows are still there and you can re-attach to them later.
  • To scroll window, press Ctrl + a + [ or Ctrl + a + esc to enter Copy Mode, then scroll up/down using keys j or k or:
   C-u -  Scrolls a half page up
   C-b -  Scrolls a full page up
   C-d -  Scrolls a half page down
   C-f -  Scrolls the full page down

Tweaks

To make your screen a little easier to use, add these lines to the appropriate files and your screen will show a status bar at the bottom with a list of programs running, time, date, etc.

~/.screenrc

# this is the command used to start a new shell.  The "-" in front means
# it will be a login shell (and will process normal bash startup files).
shell -/bin/bash

defscrollback 2048
vbell off
msgwait 1
msgminwait 1

#dynamic titles
shelltitle '$ | bash'

#Display date and other information in colorred window
hardstatus on
hardstatus alwayslastline
hardstatus string "%{.bW}%-w%{.rW}%n %t%{-}%+w %=%{..G} %{..Y} %Y/%m/%d %0c:%s%A "

~/.bashrc

# PS1 with the escape sequence for dynamic titles in screen
export PS1='\[\033k\033\\\][\u@\h: \w]\$ '

Bluetooth

sudo apt-get install obextool gnome-vfs-obexftp blueman

Statically linking executable

 ./configure LDFLAGS=-static 
 make LDFLAGS=-all-static 
shell.1275656264.txt.gz · Last modified: by admin