UNIX Productivity Hints

The following keystrokes are widely available in UNIX programs. All are supported by Emacs; subsets are supported by tcsh, Netscape, MATLAB, IDL, Pine, and GrADS. If you get used to using them things should go much more smoothly. ``C-key'' means Control+key; ``M-key'' means Meta+key or Alt+key (depending on the application). ``Meta'' is the diamond-shaped symbol on Sun keyboards.

key function keyfunction
C-A beginning of line M-Abeginning of sentence
C-E end of line M-Eend of sentence
C-P previous line
C-N next line
C-B back one character M-Bback one word
C-F forward one character M-Fforward one word
C-D delete character M-Ddelete word
C-T transpose two charactersM-Ttranspose two words
C-L refresh/clear/re-center screen
C-spaceset mark
C-W cut from mark
C-K cut to end of line
C-Y paste (``yank'')

Emacs

tcsh

tcsh is an enhanced version of the Berkeley UNIX C shell, csh. Unless you've previously changed your default shell with chsh, you are probably already using it. To determine your shell, use the following:

>echo $SHELL
/bin/tcsh
>

Netscape

ftp

wget, for retrieving remote groups of files quickly/easily

Wget is a command-line, non-interactive utility for retrieving remote files via ftp and http. Examples follow:

warm:~>wget www.cnn.com
--11:13:52--  http://www.cnn.com:80/
           => `index.html'
Connecting to www.cnn.com:80... connected!
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]

    0K -> .......... .......... .......... .......... ..........
   50K -> .......... ....

11:13:52 (187.33 KB/s) - `index.html' saved [66372]

warm:~>
warm:~>
warm:~>wget ftp://ftp.atmos.washington.edu/david/JBS_98.ps
--11:21:05--  ftp://ftp.atmos.washington.edu:21/david/JBS_98.ps
           => `JBS_98.ps'
Connecting to ftp.atmos.washington.edu:21... connected!
Logging in as anonymous ... Logged in!
==> TYPE I ... done.  ==> CWD david ... done.
==> PORT ... done.    ==> RETR JBS_98.ps ... done.
Length: 348,200 (unauthoritative)

    0K -> .......... .......... .......... .......... .......... [ 14%]
   50K -> .......... .......... .......... .......... .......... [ 29%]
  100K -> .......... .......... .......... .......... .......... [ 44%]
  150K -> .......... .......... .......... .......... .......... [ 58%]
  200K -> .......... .......... .......... .......... .......... [ 73%]
  250K -> .......... .......... .......... .......... .......... [ 88%]
  300K -> .......... .......... .......... ..........            [100%]

11:21:07 (501.53 KB/s) - `JBS_98.ps' saved [348200]

warm:~>
warm:~>
warm:~>mkdir lecturenotes
warm:~>cd lecturenotes/
warm:~/lecturenotes>foreach pagenumber (1 2 9 10)
foreach? wget http://www.atmos.washington.edu/my/class/lecture4/page${pagenumber}.ps
foreach? end
--11:27:18--  http://www.atmos.washington.edu:80/my/class/lecture4/page1.ps
           => `page1.ps'
Connecting to www.atmos.washington.edu:80... connected!
HTTP request sent, awaiting response... 404 Not Found
11:27:19 ERROR 404: Not Found.

--11:27:19--  http://www.atmos.washington.edu:80/my/class/lecture4/page2.ps
           => `page2.ps'
Connecting to www.atmos.washington.edu:80... connected!
HTTP request sent, awaiting response... 404 Not Found
11:27:19 ERROR 404: Not Found.

...

warm:~/lecturenotes>ls -l
-rw-rw-r--    1 fleminra uucp            0 Oct 26 11:28 page1
-rw-rw-r--    1 fleminra uucp            0 Oct 26 11:28 page10
-rw-rw-r--    1 fleminra uucp            0 Oct 26 11:28 page2
-rw-rw-r--    1 fleminra uucp            0 Oct 26 11:28 page9
warm:~/lecturenotes>
warm:~/lecturenotes>
warm:~/lecturenotes>wget 'ftp://ftp.data.org/pub/data*.ps'
If the filenames that you want have the form aaa.bbb.ccc.ddd.eee
you will need to use multiple wild cards aaa.*.*.*.eee  

warm:~/lecturenotes>

One of the above scripts uses the "foreach" loop and another uses a
"*" wildcard.  The following uses both.

foreach year ( 1982 1983 )
foreach month ( jan feb mar )
set filename=ftp://daac.gsfc.nasa.gov/data/avhrr/global_1dg/${year}/${month}/avhrrpf.ndvi.1nmegl.
wget $filename'*'
end
end
 
yields an output: 
--17:03:58-- -->
--ftp://daac.gsfc.nasa.gov/data/avhrr/global_1dg/1982/jan/avhrrpf.ndvi.1nmegl.*
           => `.listing'
Resolving daac.gsfc.nasa.gov... done.
Connecting to daac.gsfc.nasa.gov[192.107.190.139]:21... connected.
Logging in as anonymous ... Logged in!
==> SYST ... done.    ==> PWD ... done.
==> TYPE I ... done.  ==> CWD /data/avhrr/global_1dg/1982/jan
... done.
==> PORT ... done.    ==> LIST ... done.

    [ <=>                                                           ]
    1,357          1.29M/s             

17:04:00 (1.29 MB/s) - `.listing' saved [1357]

Removed `.listing'.

...

45 nino% ls 
avhrrpf.ndvi.1nmegl.8201.gz
avhrrpf.ndvi.1nmegl.8202.gz
avhrrpf.ndvi.1nmegl.8203.gz
avhrrpf.ndvi.1nmegl.8301.gz
avhrrpf.ndvi.1nmegl.8302.gz
avhrrpf.ndvi.1nmegl.8303.gz


Suppose you have lots of files to pull over.  Put the filenames in a
file, "file_of_filenames".
foreach filename ( `cat file_of_filenames` )
foreach? wget http://the URL of interest/$filename
foreach? end

For pulling over whole directories in situations where the "wget"
"times out": 
wget -q -O - http://domainname/directoryname/  | wget --forced-html -i -
The "-" in the first part tells wget to output to STDOUT, the "|" tells
the shell to pipe the output of the previous part to the next part,
the "-i -" in the second part tells wget to read from STDIN (the
STDOUT from the first part).  Sean Bailey of FUTURETECH / NASA GSFC
provided this very useful information.


For wget sessions timing out, one can also use
wget --tries=n --timeout=m http://...
where "n" is the number of times to try and "m" is the number of
seconds to wait before "timing out."  Harry Edmon provided this solution.

It is common now for data files to be written with one directory per
year of data.  To pull over just the data files, and not the directory
trees: 
wget -r http://directoryname --no-directories --accept nc 
This will also work for ftp.  The "accept" option says only bring over
files with the .nc extension.



September 2012
Todd Mitchell (mitchell@atmos.washington.edu)
JISAO