Unix Commands

To extract a tar file (.tar):
tar -xvf filename

To extract a gzipped tar file (.gz):
gunzip -dv filename

To extract a gzipped tar file (.tar.gz):
tar zxvf filename

To create a zipped tar file (.tar.ga):
tar -cf archivename.tar
<which_files>
gzip archivename.tar

To get info on dir sizes:
(-h is human readout, -s is summary)
du -hs *

To get volume disc sizes
(-h is human readout)
df -h

To securely transfer a file:
(-p is preserve dates, -r is recursive)
scp -pr [[user@]host]:filesource [[user@]host]:filedest
example: this will copy getfile.txt from my remote computer
to my local computer's current directory...
scp danielg@acs.bu.edu:~/getfile.txt ./

To make a symbolic link
ln -s srcdir destdir

To kill a process
1. ps
2. kill ### <-- the number of the process
OR
1. top
2. u  ... username
3. ### <-- the number of the process
4. 9  <-- to kill

To setup remote windowing
1. on local machine:
        xhost +<machinename>
2. on remote machine:
        echo $DISPLAY
3. if something there, then:
        unsetenv DISPLAY
4. either way:
        setenv DISPLAY <localmachinename>:0.0

To watch a movie:
xmovie <filename>

To make a movie of assorted single images:
convert filename*.jpg moviename.mpg

To find out where an alias points type:
which <aliasname>

To schedule a command script at a time enter:
at -f <scriptname> TIME
the time can be in a number of formats that are easy to understand.

To use a screen across multiple terminals:
This is useful for lots of stuff. One good use is controlling a computer
remotely. If you lose connection, the process continues to run, and you
can reconnect to it later. The command is...
screen
Help:
control-a then ?
Detach (leave it running but go away) from within:
control-a then d
To reattach later:
screen -r
To show connect to a screen already on (mirror it!)
screen -x
To add multiple screens, you do the "screen" option while inside:
control-a then control-c
To cycle between screens within (screen numbers start from 0)
control-a then ### <the screen number>

To check mail:
ckmail

To run matlab from the commandline:
matlab < (filename) > (outfile)
So for instance if I want to run the smov command...
matlab < smov('cow','moo') > out.txt

To make unix scripts:
Lots of cool info available in man bash.
Also: setting variables is VERY picky. No spaces allowed here: a="no space."
Which means a = "some space" will not work.

To kill lots o stuff:
kill -9 `ps -u $USER | awk '$2=="?" && $1 > 12000 { print $1}'`
kill the stuff in quotes, the current user's processes, the results of the
awk (a langugue) command of getting item 2 (unknown terminals) that item 1
(high process numbers) printem all one line at a time

To run a process that does not die with terminal
nohup <command>

To ftp outside NMR
ftp surfer.nmr.mgh.harvard.edu
put files to the incoming folder
it takes 15 minutes to show up
locally, the files are at:
/space/incoming

VNC is an excellent way to remotely control a screen.
Step 1: run the vncserver from the host computer.
Step 2: run the vncviewer from the remote accessing computer.
In NMR, there is a firewall, so SSH Tunneling is needed.
vncviwer
vncpassword
vncserver
1. make sure VNC server is running on doodles:
vncserver
2. port forwarding through gate to doodles:
ssh -L 5901:doodles.nmr.mgh.harvard.edu:5901
daniel@gate.nmr.mgh.harvard.edu
3. run the viewer.
vncviewer
localhost:1

How to batch rename
rename <patternOLD> <patternNEW> <whichfiles>
example:
        rename boo moo *jellyfiles*
The above example will look at all files matching *jellyfiles* and rename the "boo" to a "moo" in the filenames.
 
To search for any text file which contains the string 'elephant juice' in the current dir:
grep -H 'elephant juice' *
 
To set up SSH and SCP without passwords: (NOT RECOMMENDED!!!)
1. generate an RSA key set locally:
ssh-keygen -t rsa
2. Copy the public key to your remote computer
    2a. If you have no public keys over there, do this:
    scp ~/.ssh/id_rsa.pub [remote_login_name@]remote_computer_name:~/.ssh/authorized_keys
    2b. If you already have some, do this instead:
    cat ~/.ssh/id_rsa.pub | ssh [remote_login_name@]remote_computer_name 'cat >>~/.ssh/authorized_keys'
Now you can SSH and SCP without a login password.

How to switch KDE as default session...
switchdesk kde

How to send an email via a command prompt:
echo "This is the text of the message." | mail -s "Message subject" user@location.com