home *** CD-ROM | disk | FTP | other *** search
/ Hackers Toolkit v2.0 / Hackers_Toolkit_v2.0.iso / HTML / archive / Unix / HOWTOs / VMS-TO-L < prev    next >
Text File  |  1999-11-04  |  52KB  |  1,981 lines

  1.   From VMS to Linux HOWTO
  2.   By Guido Gonzato, guido@ibogfs.cineca.it
  3.   v1.0.2, 20 April 1998
  4.  
  5.   This HOWTO is aimed at all those who have been using VMS and now need
  6.   or want to switch to Linux, the free UNIX clone. The transition is
  7.   made (hopefully) painless with a step--to--step comparison between
  8.   commands and available tools.
  9.   ______________________________________________________________________
  10.  
  11.   Table of Contents
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.   1. Introduction
  68.  
  69.      1.1 Why Linux?
  70.      1.2 Comparing Commands and Files
  71.  
  72.   2. Short Intro
  73.  
  74.      2.1 Files
  75.      2.2 Directories
  76.      2.3 Programs
  77.      2.4 Quick Tour
  78.  
  79.   3. Editing Files
  80.  
  81.   4. TeXing
  82.  
  83.   5. Programming
  84.  
  85.      5.1 Fortran
  86.      5.2 Using
  87.      5.3 Shell Scripts
  88.      5.4 C
  89.  
  90.   6. Graphics
  91.  
  92.   7. Mail and Internet Tools
  93.  
  94.   8. Advanced Topics
  95.  
  96.      8.1 Permissions and Ownership
  97.      8.2 Multitasking: Processes and Jobs
  98.      8.3 Files, Revisited
  99.      8.4 Print Queues
  100.  
  101.   9. Configuring
  102.  
  103.   10. Useful Programs
  104.  
  105.      10.1 Browsing Files:
  106.      10.2 RCS in a Nutshell
  107.         10.2.1 Using the latest version
  108.         10.2.2 Creating a new version
  109.         10.2.3 Comparing versions
  110.         10.2.4 Using an old version
  111.      10.3 Archiving: tar & gzip
  112.  
  113.   11. Real Life Examples
  114.  
  115.   12. Tips You Can't Do Without
  116.  
  117.   13. The End
  118.  
  119.      13.1 Copyright
  120.  
  121.   14. Disclaimer
  122.  
  123.  
  124.  
  125.   ______________________________________________________________________
  126.  
  127.   1.  Introduction
  128.  
  129.   1.1.  Why Linux?
  130.  
  131.  
  132.  
  133.   You've heard that UNIX is difficult and balk at the prospect of
  134.   leaving VMS, don't you? Don't worry. Linux, one of the finest UNIX
  135.   clones, is not more difficult to use than VMS; actually, I find it
  136.   easier. Although VMS aficionados may not agree, in many people's
  137.   opinion Linux is much more powerful and versatile.
  138.  
  139.   Linux and VMS are both good operating systems and accomplish
  140.   essentially the same tasks, but Linux' tools are (IMHO) superior, its
  141.   syntax is often much more concise, and has some features missing in
  142.   VMS that help save a lot of time. (You'll often hear that VMS and UNIX
  143.   have a different `philosophy'.)  Moreover, Linux is available for PCs
  144.   while VMS is not, and modern Pentium-based Linux machines can
  145.   outperform a VAX. The icing on the cake is the excellent performance
  146.   of modern video cards, which turn an X11-based Linux box into a fast
  147.   graphic workstation; nearly always, quicker than dedicated machines.
  148.  
  149.   I have many reasons to believe that the combination Pentium + Linux is
  150.   preferable to VAX--VMS, but preferences are a strictly personal matter
  151.   and you may disagree. You'll decide by yourself after a few months.
  152.  
  153.   I imagine you're a university researcher or a student, and that you
  154.   use VMS for the following everyday tasks:
  155.  
  156.  
  157.   ╖  writing papers with TeX/LaTeX;
  158.  
  159.   ╖  programming in Fortran;
  160.  
  161.   ╖  doing some graphics;
  162.  
  163.   ╖  using Internet services;
  164.  
  165.   ╖  et cetera.
  166.  
  167.   In the following sections I'm going to explain to you how to do these
  168.   tasks under Linux, exploiting your experience with VMS. Prerequisites:
  169.  
  170.  
  171.   ╖  Linux and X Window System are properly installed;
  172.  
  173.   ╖  there's a system administrator to take care of the technical
  174.      details (please get help from them, not from me ;-) ;
  175.  
  176.   ╖  your shell---the equivalent of DCL---is bash (ask your sysadm).
  177.  
  178.   Please note that this HOWTO is not enough to acquaint you fully with
  179.   Linux: it only contains the bare essential to get you started. You
  180.   should learn more about Linux to make the most of it (advanced bash
  181.   features, programming, regular expressions...). From now on, RMP means
  182.   `please read the man pages for further details'. The man pages are the
  183.   equivalent of the command HELP.
  184.  
  185.   The Linux Documentation Project documents, available on
  186.   sunsite.unc.edu:/pub/Linux/docs/LDP, are an important source of
  187.   information. I suggest that you read Larry Greenfield's ``Linux User
  188.   Guide''---it's invaluable for the novice user.
  189.  
  190.   And now, go ahead.
  191.  
  192.  
  193.   1.2.  Comparing Commands and Files
  194.  
  195.  
  196.   This table attempts to compare VMS' and Linux' most used commands.
  197.   Please keep in mind that the syntax is often very different; for more
  198.   details, refer to the following sections.
  199.        VMS                             Linux                   Notes
  200.        ------------------------------------------------------------------------------
  201.  
  202.        @COMMAND                        command                 must be executable
  203.        COPY file1 file2                cp file1 file2
  204.        CREATE/DIR [.dirname]           mkdir dirname           only one at a time
  205.        CREATE/DIR [.dir1.dir2]         mkdirhier dir/name
  206.        DELETE filename                 rm filename
  207.        DIFF file1 file2                diff -c file1 file2
  208.        DIRECTORY                       ls
  209.        DIRECTORY [...]file             find . -name file
  210.        DIRECTORY/FULL                  ls -al
  211.        EDIT filename                   vi filename,            you won't like it
  212.                                        emacs filename,         EDT compatible
  213.                                        jed filename            ditto---my favourite
  214.        FORTRAN prog.for                g77 prog.f,             no need to do LINK
  215.                                        f77 prog.f,
  216.                                        fort77 prog.f
  217.        HELP command                    man command             must specify `command'
  218.                                        info command            ditto
  219.        LATEX file.tex                  latex file.tex
  220.        LOGIN.COM                       .bash_profile,          `hidden' file
  221.                                        .bashrc                 ditto
  222.        LOGOUT.COM                      .bash_logout            ditto
  223.        MAIL                            mail,                   crude
  224.                                        elm,                    much better
  225.                                        pine                    better still
  226.        PRINT file.ps                   lpr file.ps
  227.        PRINT/QUEUE=laser file.ps       lpr -Plaser file.ps
  228.        PHONE user                      talk user
  229.        RENAME file1 file2              mv file1 file2          not for multiple files
  230.        RUN progname                    progname
  231.        SEARCH file "pattern"           grep pattern file
  232.        SET DEFAULT [-]                 cd ..
  233.        SET DEFAULT [.dir.name]         cd dir/name
  234.        SET HOST hostname               telnet hostname,        not exactly the same
  235.                                        rlogin hostname
  236.        SET FILE/OWNER_UIC=joe          chown joe file          completely different
  237.        SET NOBROADCAST                 mesg
  238.        SET PASSWORD                    passwd
  239.        SET PROT=(perm) file            chmod perm file         completely different
  240.        SET TERMINAL                    export TERM=            different syntax
  241.        SHOW DEFAULT                    pwd
  242.        SHOW DEVICE                     du, df
  243.        SHOW ENTRY                      lpq
  244.        SHOW PROCESS                    ps -ax
  245.        SHOW QUEUE                      lpq
  246.        SHOW SYSTEM                     top
  247.        SHOW TIME                       date
  248.        SHOW USERS                      w
  249.        STOP                            kill
  250.        STOP/QUEUE                      kill,                   for processes
  251.                                        lprm                    for print queues
  252.        SUBMIT command                  command &
  253.        SUBMIT/AFTER=time command       at time command
  254.        TEX file.tex                    tex file.tex
  255.        TYPE/PAGE file                  more file
  256.                                        less file               much better
  257.  
  258.  
  259.  
  260.  
  261.   But of course it's not only a matter of different command names. Read
  262.   on.
  263.  
  264.  
  265.   2.  Short Intro
  266.  
  267.  
  268.   This is what you absolutely need to know before logging in the first
  269.   time. Relax, it's not much.
  270.  
  271.  
  272.   2.1.  Files
  273.  
  274.  
  275.  
  276.   ╖  Under VMS filenames are in the form filename.extension.version;.
  277.      Under Linux, the version number doesn't exist (big limitation, but
  278.      see Section ``RCS in a Nutshell''); the filename has normally a
  279.      limit of 255 characters and can have as many dots as you like.
  280.      Example of filename: This.is_a_FILEname.txt.
  281.  
  282.   ╖  Linux distinguishes between upper case and lower case characters:
  283.      FILENAME.txt and filename.txt are two different files; ls is a
  284.      command, LS is not.
  285.  
  286.   ╖  A filename starting with a dot is a `hidden' file (that is, it
  287.      won't normally show up in dir listings), while filenames ending
  288.      with a tilde '~' represent backup files.
  289.  
  290.  
  291.   Now, a table to sum up how to translate commands from VMS to Linux:
  292.  
  293.  
  294.  
  295.  
  296.        VMS                                     Linux
  297.        ---------------------------------------------------------------------
  298.  
  299.        $ COPY file1.txt; file2.txt;            $ cp file1.txt file2.txt
  300.        $ COPY [.dir]file.txt;1 []              $ cp dir/file.txt .
  301.        $ COPY [.dir]file.txt;1 [-]             $ cp dir/file.txt ..
  302.        $ DELETE *.dat.*                        $ rm *dat
  303.        $ DIFF file1 file2                      $ diff -c file1 file2
  304.        $ PRINT file                            $ lpr file
  305.        $ PRINT/queue=queuename file            $ lpr -Pprintername file
  306.        $ SEARCH *.tex.* "geology"          $ grep geology *tex
  307.  
  308.  
  309.  
  310.  
  311.   For other examples involving directories, see below; for details about
  312.   protections, ownership, and advanced topics, see Section ``Advanced
  313.   Topics''.
  314.  
  315.  
  316.   2.2.  Directories
  317.  
  318.  
  319.  
  320.   ╖  Within the same node and device, directories names under VMS are in
  321.      the form [top.dir.subdir]; under Linux, /top/dir/subdir/. On the
  322.      top of the directory tree lies the so--called `root directory'
  323.      called /; underneath there are other directories like /bin, /usr,
  324.      /tmp, /etc, and others.
  325.  
  326.   ╖  The directory /home contains the so--called users' `home
  327.      directories': e.g. /home/guido, /home/warner, and so on.  When a
  328.      user logs in, they start working in their home dir; it's the
  329.      equivalent of SYS$LOGIN. There's a shortcut for the home directory:
  330.      the tilde '~'. So, cd ~/tmp is the same as, say, cd
  331.      /home/guido/tmp.
  332.  
  333.   ╖  Directory names follow the same rules as file names. Furthermore,
  334.      each directory has two special entries: one is . and refers to the
  335.      directory itself (like []), and .. that refers to the parent
  336.      directory (like [-]).
  337.  
  338.  
  339.   And now for some other examples:
  340.  
  341.  
  342.  
  343.  
  344.        DOS                                     Linux
  345.        ---------------------------------------------------------------------
  346.  
  347.        $ CREATE/DIR [.dirname]                 $ mkdir dirname
  348.        $ CREATE/DIR [.dir1.dir2.dir3]          $ mkdirhier dir1/dir2/dir3
  349.           n/a                                  $ rmdir dirname
  350.                                                (if dirname is empty)
  351.                                                $ rm -R dirname
  352.        $ DIRECTORY                             $ ls
  353.        $ DIRECTORY [...]file.*.*               $ find . -name "file*"
  354.        $ SET DEF SYS$LOGIN                     $ cd
  355.        $ SET DEF [-]                           $ cd ..
  356.        $ SET DEF [top.dir.subdir]              $ cd /top/dir/subdir
  357.        $ SET DEF [.dir.subdir]                 $ cd dir/subdir
  358.        $ SHOW DEF                              $ pwd
  359.  
  360.  
  361.  
  362.  
  363.   For protections, ownership, and advanced topics, see Section
  364.   ``Advanced Topics''.
  365.  
  366.  
  367.   2.3.  Programs
  368.  
  369.  
  370.  
  371.   ╖  Commands, compiled programs, and shell scripts (VMS' `command
  372.      files') don't have compulsory extensions like .EXE or .COM and can
  373.      be called whatever you like. Executable files are marked by an
  374.      asterisk '*' when you issue ls -F.
  375.  
  376.   ╖  To run an executable file, just type its name (no RUN PROGRAM.EXE
  377.      or @COMMAND). Caveat: it's essential that the file be located in a
  378.      directory included in the path of executables, which is a list of
  379.      directories. Typically, the path includes dirs like /bin, /usr/bin,
  380.      /usr/X11R6/bin, and others. If you write your own programs, put
  381.      them in a directory you have included in the path (see how in
  382.      Section ``Configuring''). As an alternative, you may run a program
  383.      specifying its complete path: e.g., /home/guido/data/myprog; or
  384.      ./myprog, if the current directory isn't in the path.
  385.  
  386.   ╖  Command switches are obtained with /OPTION= under VMS, and with
  387.      -switch or --switch under Linux, where switch is a letter, more
  388.      letters combined, or a word. In particular, the switch -R
  389.      (recursive) of many Linux commands performs the same action as
  390.      [...]  under VMS;
  391.  
  392.   ╖  You can issue several commands on the command line:
  393.  
  394.  
  395.  
  396.  
  397.   $ command1 ; command2 ; ... ; commandn
  398.  
  399.  
  400.  
  401.  
  402.  
  403.   ╖  Most of the flexibility of Linux comes from two features awkwardly
  404.      implemented or missing in VMS: I/O redirection and piping. (To be
  405.      sincere, I have been told that recent versions of IDL support
  406.      redirection and piping. I don't have that version.) Redirection is
  407.      a side feature under VMS (remember the switch /OUTPUT= of many
  408.      commands), or a fastidious process, like:
  409.  
  410.  
  411.  
  412.        $ DEFINE /USER SYS$OUTPUT OUT
  413.        $ DEFINE /USER SYS$INPUT IN
  414.        $ RUN PROG
  415.  
  416.  
  417.  
  418.  
  419.  
  420.   which has the simple Linux (UNIX) equivalent:
  421.  
  422.  
  423.  
  424.        $ prog < in > out
  425.  
  426.  
  427.  
  428.  
  429.  
  430.   Piping is simply impossible under VMS, but has a key role under UNIX.
  431.   A typical example:
  432.  
  433.  
  434.  
  435.        $ myprog < datafile | filter_1 | filter_2 >> result.dat 2> errors.log &
  436.  
  437.  
  438.  
  439.  
  440.  
  441.   which means: the program myprog gets its input from the file datafile
  442.   (via <), its output is piped (via |) to the program filter_1 that
  443.   takes it as input and processes it, the resulting output is piped
  444.   again to filter_2 for further processing, the final output is appended
  445.   (via >>) to the file result.dat, and error messages are redirected
  446.   (via 2>) onto the file errors.log. All this in background (& at the
  447.   end of the command line). More about this in Section ``Examples''.
  448.  
  449.  
  450.   For multitasking, `queues', and the like, see Section ``Advanced
  451.   Topics''.
  452.  
  453.  
  454.   2.4.  Quick Tour
  455.  
  456.  
  457.   Now you are ready to try Linux out. Enter your login name and password
  458.   exactly as they are. For example, if your login name and password are
  459.   john and My_PassWd, don't type John or my_passwd.  Remember, UNIX
  460.   distinguishes between capital and small letters.
  461.  
  462.  
  463.   Once you've logged in, you'll see a prompt; chances are it'll be
  464.   something like machinename:$. If you want to change the prompt or make
  465.   some programs start automatically, you'll have to edit a `hidden' file
  466.   called .profile or .bash_profile (see example in Section
  467.   ``Configuring''). This is the equivalent of LOGIN.COM.
  468.  
  469.   Pressing ALT--F1, ALT--F2, ... ALT--F6 switches between `virtual
  470.   consoles'.  When one VC is busy with a full--screen application, you
  471.   can flip over to another and continue to work. Try and log in to
  472.   another VC.
  473.  
  474.   Now you may want to start X Window System (from now on, X). X is a
  475.   graphic environment very similar to DECWindows---actually, the latter
  476.   derives from the former. Type the command startx and wait a few
  477.   seconds; most likely you'll see an open xterm or equivalent terminal
  478.   emulator, and possibly a button bar. (It depends on how your sysadm
  479.   configured your Linux box.)  Click on the desktop (try both mouse
  480.   buttons) to see a menu.
  481.  
  482.   While in X, to access the text mode (`console') sessions press
  483.   CTRL--ALT--F1 ... CTRL--ALT--F6. Try it. When in console, go back to X
  484.   pressing ALT--F7. To quit X, follow the menu instructions or press
  485.   CTRL--ALT--BS.
  486.  
  487.   Type the following command to list your home dir contents, including
  488.   the hidden files:
  489.  
  490.  
  491.  
  492.        $ ls -al
  493.  
  494.  
  495.  
  496.  
  497.   Press SHIFT--PAG UP to back-scroll. Now get help about the ls command
  498.   typing:
  499.  
  500.  
  501.  
  502.        $ man ls
  503.  
  504.  
  505.  
  506.  
  507.   pressing 'q' to exit. To end the tour, type exit to quit your session.
  508.   If now you want to turn off your PC, press CTRL--ALT--DEL and wait a
  509.   few seconds (never switch off the PC while in Linux! You could damage
  510.   the filesystem.)
  511.  
  512.   If you think you're ready to work, go ahead, but if I were you I'd
  513.   jump to Section ``Advanced Topics''.
  514.  
  515.  
  516.  
  517.   3.  Editing Files
  518.  
  519.  
  520.   Linux doesn't have EDT, but there are scores of editors available. The
  521.   only one that's guaranteed to be included in every UNIX version is
  522.   vi---forget it, your sysadm must have installed something better.
  523.   Probably the most popular editor is emacs, which can emulate EDT to a
  524.   certain degree; jed is another editor that provides EDT emulation.
  525.  
  526.   These two editors are particularly useful for editing program sources,
  527.   since they have two features unknown to EDT: syntax hilighting and
  528.   automatic indentation. Moreover, you can compile your programs from
  529.   within the editor (command ESC-X compile); in case of a syntax error,
  530.   the cursor will be positioned on the offending line. I bet that you'll
  531.   never want to use the true blue EDT again.
  532.  
  533.   If you have emacs: start it, then type ESC-X edt-emulation-on.
  534.   Pressing ALT--X or ESC-X is emacs' way of issuing commands, like EDT's
  535.   CTRL--Z. From now on, emacs acts like EDT apart from a few commands.
  536.   Differences:
  537.  
  538.  
  539.   ╖  don't press CTRL--Z to issue commands (if you did, you stopped
  540.      emacs. Type fg to resume it);
  541.  
  542.   ╖  there's an extensive on-line help. Press CTRL-H ?, or CTRL-H T to
  543.      start a tutorial;
  544.  
  545.   ╖  to save a file, press CTRL-X CTRL-S;
  546.  
  547.   ╖  to exit, press CTRL-X CTRL-C;
  548.  
  549.   ╖  to insert a new file in a buffer, press CTRL-X CTRL-F, then CTRL-X
  550.      B to switch among buffers.
  551.  
  552.   If you have jed: ask your sysadm to configure jed properly.  Emulation
  553.   is already on when you start it; use the normal keypad keys, and press
  554.   CTRL--H CTRL--H or CTRL-? to get help. Commands are issued in the same
  555.   way as emacs'. In addition, there are some handy key bindings missing
  556.   in the original EDT; key bindings can also be tailored to your own
  557.   taste. Ask your sysadm.
  558.  
  559.   In alternative, you may use another editor with a completely different
  560.   interface. emacs in native mode is an obvious choice; another popular
  561.   editor is joe, which can emulate other editors like emacs itself
  562.   (being even easier to use) or the DOS editor. Invoke the editor as
  563.   jmacs or jstar and press, respectively, CTRL-X H or CTRL-J to get
  564.   online help. emacs and jed are much more powerful than good ol' EDT.
  565.  
  566.  
  567.  
  568.   4.  TeXing
  569.  
  570.  
  571.   TeX and LaTeX are identical to their VMS counterparts---only quicker
  572.   :-), but the tools to handle the .dvi and .ps files are superior:
  573.  
  574.  
  575.   ╖  to run a TeX file through TeX, do as usual: tex file.tex;
  576.  
  577.   ╖  to turn a .dvi file into a .ps file, type dvips -o filename.ps
  578.      filename.dvi;
  579.  
  580.   ╖  to visualize a .dvi file, type within an X session: xdvi
  581.      filename.dvi &. Click on the page to magnify. This program is
  582.      smart: if you edit and run TeX producing newer versions of the .dvi
  583.      file, xdvi will update it automatically;
  584.  
  585.   ╖  to visualize a .ps file, type within an X session: ghostview
  586.      filename.ps &. Click on the page to magnify. The whole document or
  587.      selected pages can be printed. A newer and better program is gv.
  588.  
  589.   ╖  to print the .ps: usually the command lpr mypaper.ps will do, but
  590.      if the PostScript printer is called, say, `ps' (ask your sysadm)
  591.      you'll do: lpr -Pps mypaper.ps. For more information about print
  592.      queues, go to Section ``Print Queues''.
  593.  
  594.  
  595.   5.  Programming
  596.  
  597.  
  598.   Programming under Linux is much better: there are lots of tools that
  599.   make programming easier and quicker. For instance, the drudgery of
  600.   editing--saving--exiting--compiling--re-editing can be cut short by
  601.   using editors like emacs or jed, as seen above.
  602.  
  603.  
  604.   5.1.  Fortran
  605.  
  606.  
  607.   Not substantial differences here, but note that at the time of writing
  608.   the available (free) compilers are not 100% compatible with VMS';
  609.   expect some minor quirks. (It's actually the VMS compiler which has
  610.   non-standard extensions.) See /usr/doc/g77/DOC or /usr/doc/f2c/f2c.ps
  611.   for details.
  612.  
  613.   Your sysadm has installed a native compiler called g77 (good but, as
  614.   of version 0.5.21, still not perfectly compatible with DEC Fortran) or
  615.   possibly the Fortran to C translator, f2c, and one of the front-ends
  616.   that make it mimic a native compiler. In my experience, the package
  617.   yaf77 is the one that provides best results.
  618.  
  619.   To compile a Fortran program with g77, edit the source, save it with
  620.   extension .f, then do:
  621.  
  622.  
  623.  
  624.        $ g77 myprog.f
  625.  
  626.  
  627.  
  628.  
  629.   which creates by default an executable called a.out (you don't have to
  630.   link anything). To give the executable a different name and do some
  631.   optimisation:
  632.  
  633.  
  634.  
  635.        $ g77 -O2 -o myprog myprog.f
  636.  
  637.  
  638.  
  639.  
  640.   Beware of optimisations! Ask your sysadm to read the documentation
  641.   that comes with the compiler and tell you if there are any problems.
  642.  
  643.   To compile a subroutine:
  644.  
  645.  
  646.  
  647.        $ g77 -c mysub.f
  648.  
  649.  
  650.  
  651.  
  652.   This creates a file mysub.o. To link this subroutine to a program,
  653.   you'll do
  654.  
  655.  
  656.  
  657.        $ g77 -o myprog myprog.f mysub.o
  658.  
  659.  
  660.  
  661.   If you have many external subroutines and you want to make a library,
  662.   do the following:
  663.  
  664.  
  665.  
  666.        $ cd subroutines/
  667.        $ cat *f >mylib.f ; g77 -c mylib.f
  668.  
  669.  
  670.  
  671.  
  672.   This will create mylib.o that you can link to your programs.
  673.  
  674.   Finally, to link an external library called, say, libdummy.so:
  675.  
  676.  
  677.  
  678.        $ g77 -o myprog myprog.f -ldummy
  679.  
  680.  
  681.  
  682.  
  683.   If you have f2c, you only have to use f77 or fort77 instead of g77.
  684.  
  685.   Another useful programming tool is make, described below.
  686.  
  687.  
  688.  
  689.   5.2.  Using make
  690.  
  691.  
  692.   The utility make is a tool to handle the compilation of programs that
  693.   are split into several source files.
  694.  
  695.   Let's suppose you have source files containing your routines,
  696.   file_1.f, file_2.f, file_3.f, and a source file of the main program
  697.   that uses the routines, myprog.f. If you compile your program
  698.   manually, whenever you modify one of the source files you have to
  699.   figure out which file depends on which, which file to recompile first,
  700.   and so on.
  701.  
  702.   Instead of getting mad, you can write a `makefile'. This is a text
  703.   file containing the dependencies between your sources: when one is
  704.   modified, only the ones that depend on the modified file will be
  705.   recompiled.
  706.  
  707.   In our example, you'd write a makefile like this:
  708.  
  709.  
  710.  
  711.  
  712.  
  713.  
  714.  
  715.  
  716.  
  717.  
  718.  
  719.  
  720.  
  721.  
  722.  
  723.  
  724.  
  725.  
  726.  
  727.   ______________________________________________________________________
  728.  
  729.   # This is makefile
  730.   # Press the <TAB> key where you see <TAB>!
  731.   # It's important: don't use spaces instead.
  732.  
  733.   myprog: myprog.o file_1.o file_2.o file_3.o
  734.   <TAB>g77 -o myprog myprog.o file_1.o file_2.o file_3.o
  735.   # myprog depends on four object files
  736.  
  737.   myprog.o: myprog.f
  738.   <TAB>g77 -c myprog.f
  739.   # myprog.o depends on its source file
  740.  
  741.   file_1.o: file_1.f
  742.   <TAB>g77 -c file_1.f
  743.   # file_1.o depends on its source file
  744.  
  745.   file_2.o: file_2.f file_1.o
  746.   <TAB>g77 -c file_2.f file_1.o
  747.   # file_2.o depends on its source file and an object file
  748.  
  749.   file_3.o: file_3.f file_2.o
  750.   <TAB>g77 -c file_3.f file_2.o
  751.   # file_3.o depends on its source file and an object file
  752.  
  753.   # end of makefile.
  754.   ______________________________________________________________________
  755.  
  756.  
  757.  
  758.   Save this file as Makefile and type make to compile your program;
  759.   alternatively, save it as myprog.mak and type make -f myprog.mak.  And
  760.   of course, RMP.
  761.  
  762.  
  763.  
  764.   5.3.  Shell Scripts
  765.  
  766.  
  767.   Shell scripts are the equivalent of VMS' command files and, for a
  768.   change, are much more powerful.
  769.  
  770.   To write a script, all you have to do is write a standard ASCII file
  771.   containing the commands, save it, then make it executable with the
  772.   command chmod +x <scriptfile>. To execute it, type its name.
  773.  
  774.   Writing scripts under bash is such a vast subject it would require a
  775.   book by itself, and I will not delve into the topic any further. I'll
  776.   just give you a more-or-less comprehensive and (hopefully) useful
  777.   example you can extract some basic rules from.
  778.  
  779.   EXAMPLE: sample.sh
  780.  
  781.  
  782.  
  783.  
  784.  
  785.  
  786.  
  787.  
  788.  
  789.  
  790.  
  791.  
  792.  
  793.   ______________________________________________________________________
  794.   #!/bin/sh
  795.   # sample.sh
  796.   # I am a comment
  797.   # don't change the first line, it must be there
  798.   echo "This system is: `uname -a`" # use the output of the command
  799.   echo "My name is $0" # built-in variables
  800.   echo "You gave me the following $# parameters: "$*
  801.   echo "First parameter is: "$1
  802.   echo -n "What's your name? " ; read your_name
  803.   echo notice the difference: "hi $your_name" # quoting with "
  804.   echo notice the difference: 'hi $your_name' # quoting with '
  805.   DIRS=0 ; FILES=0
  806.   for file in `ls .` ; do
  807.     if [ -d ${file} ] ; then # if file is a directory
  808.       DIRS=`expr $DIRS + 1`  # this means DIRS = DIRS + 1
  809.     elif [ -f ${file} ] ; then
  810.       FILES=`expr $FILES + 1`
  811.     fi
  812.     case ${file} in
  813.       *.gif|*jpg) echo "${file}: graphic file" ;;
  814.       *.txt|*.tex) echo "${file}: text file" ;;
  815.       *.c|*.f|*.for) echo "${file}: source file" ;;
  816.       *) echo "${file}: generic file" ;;
  817.     esac
  818.   done
  819.   echo "there are ${DIRS} directories and ${FILES} files"
  820.   ls | grep "ZxY--!!!WKW"
  821.   if [ $? != 0 ] ; then # exit code of last command
  822.     echo "ZxY--!!!WKW not found"
  823.   fi
  824.   echo "enough... type 'man bash' if you want more info."
  825.   ______________________________________________________________________
  826.  
  827.  
  828.  
  829.  
  830.   5.4.  C
  831.  
  832.  
  833.   Linux is an excellent environment to program in C. Taken for granted
  834.   that you know C, here are a couple of guidelines. To compile your
  835.   standard hello.c you'll use the gcc compiler, which comes as part of
  836.   Linux and has the same syntax as g77:
  837.  
  838.  
  839.  
  840.        $ gcc -O2 -o hello hello.c
  841.  
  842.  
  843.  
  844.  
  845.   To link a library to a program, add the switch -l<libname>.  For
  846.   example, to link the math library and optimize do
  847.  
  848.  
  849.  
  850.        $ gcc -O2 -o mathprog mathprog.c -lm
  851.  
  852.  
  853.  
  854.  
  855.   (The -l<libname> switch forces gcc to link the library
  856.   /usr/lib/lib<libname>.a; so -lm links /usr/lib/libm.a).
  857.  
  858.  
  859.   When your program is made of several source files, you'll need to use
  860.   the utility make described above. Just use gcc and C source files in
  861.   the makefile.
  862.  
  863.   You can invoke some help about the C functions, that are covered by
  864.   man pages, section 3; for example,
  865.  
  866.  
  867.  
  868.        $ man 3 printf
  869.  
  870.  
  871.  
  872.  
  873.   There are lots of libraries available out there; among the first
  874.   you'll want to use are ncurses, to handle text mode effects, and
  875.   svgalib, to do graphics.
  876.  
  877.  
  878.  
  879.   6.  Graphics
  880.  
  881.  
  882.   Among the scores of graphic packages available, gnuplot stands out for
  883.   its power and ease of use. Go to X and type gnuplot, and have two
  884.   sample data files ready: 2D-data.dat (two data per line), and 3D-
  885.   data.dat (three data per line).
  886.  
  887.   Examples of 2-D graphs:
  888.  
  889.  
  890.  
  891.        gnuplot> set title "my first graph"
  892.        gnuplot> plot '2D-data.dat'
  893.        gnuplot> plot '2D-data.dat' with linespoints
  894.        gnuplot> plot '2D-data.dat', sin(x)
  895.        gnuplot> plot [-5:10] '2D-data.dat'
  896.  
  897.  
  898.  
  899.  
  900.   Example of 3-D graphs (each `row' of X values is followed by a blank
  901.   line):
  902.  
  903.  
  904.  
  905.        gnuplot> set parametric ; set hidden3d ; set contour
  906.        gnuplot> splot '3D-data.dat' using 1:2:3 with linespoints
  907.  
  908.  
  909.  
  910.  
  911.   A single-column datafile (e.g., a time series) can also be plotted as
  912.   a 2-D graph:
  913.  
  914.  
  915.  
  916.        gnuplot> plot [-5:15] '2D-data-1col.dat' with linespoints
  917.  
  918.  
  919.  
  920.  
  921.   or as a 3-D graph (blank lines in the datafile, as above):
  922.  
  923.  
  924.  
  925.   gnuplot> set noparametric ; set hidden3d
  926.   gnuplot> splot '3D-data-1col.dat' using 1 with linespoints
  927.  
  928.  
  929.  
  930.  
  931.   To print a graph: if the command to print on your Postscript printer
  932.   is lpr -Pps file.ps, issue:
  933.  
  934.  
  935.  
  936.        gnuplot> set term post
  937.        gnuplot> set out '| lpr -Pps'
  938.        gnuplot> replot
  939.  
  940.  
  941.  
  942.  
  943.   then type set term x11 to restore. Don't get confused---the last print
  944.   will come out only when you quit gnuplot.
  945.  
  946.   For more info, type help or see the examples in directory
  947.   /usr/lib/gnuplot/demos/, if you have it.
  948.  
  949.  
  950.  
  951.   7.  Mail and Internet Tools
  952.  
  953.  
  954.   Since Internet was born on UNIX machines, you find plenty of nice and
  955.   easy-to-use applications under Linux. Here are just some:
  956.  
  957.  
  958.   ╖  Mail: use elm or pine to handle your email; both programs have on-
  959.      line help. For short messages, you could use mail, as in mail -s
  960.      "hello mate" user@somewhere < msg.txt. You may like programs like
  961.      xmail or some such.
  962.  
  963.   ╖  Newsgroups: use tin or slrn, both very intuitive and self-
  964.      explanatory.
  965.  
  966.   ╖  ftp: apart from the usual character-based ftp, ask your sysadm to
  967.      install the full-screen ncftp or a graphical ftp client like xftp.
  968.  
  969.   ╖  WWW: the ubiquitous netscape, or xmosaic, chimera, and arena are
  970.      graphical web browsers; a character-based one is lynx, quick and
  971.      effective.
  972.  
  973.  
  974.   8.  Advanced Topics
  975.  
  976.  
  977.   Here the game gets tough. Learn these features, then you'll be ready
  978.   to say that you `know something about Linux' ;-)
  979.  
  980.  
  981.  
  982.   8.1.  Permissions and Ownership
  983.  
  984.  
  985.   Files and directories have permissions (`protections') and ownership,
  986.   just like under VMS. If you can't run a program, or can't modify a
  987.   file, or can't access a directory, it's because you don't have the
  988.   permission to do so, and/or because the file doesn't belong to you.
  989.   Let's have a look at the following example:
  990.  
  991.        $ ls -l /bin/ls
  992.        -rwxr-xr-x   1 root     bin         27281 Aug 15  1995 /bin/ls*
  993.  
  994.  
  995.  
  996.  
  997.   The first field shows the permissions of the file ls (owner root,
  998.   group bin). There are three types of ownership: owner, group, and
  999.   others (similar to VMS owner, group, world), and three types of
  1000.   permissions: read, write (and delete), and execute.
  1001.  
  1002.   From left to right, - is the file type (- = ordinary file, d =
  1003.   directory, l = link, etc); rwx are the permissions for the file owner
  1004.   (read, write, execute); r-x are the permissions for the group of the
  1005.   file owner (read, execute); r-x are the permissions for all other
  1006.   users (read, execute).
  1007.  
  1008.   To change a file's permissions:
  1009.  
  1010.  
  1011.  
  1012.        $ chmod <whoXperm> <file>
  1013.  
  1014.  
  1015.  
  1016.  
  1017.   where who is u (user, that is owner), g (group), o (other), X is
  1018.   either + or -, perm is r (read), w (write), or x (execute). Examples:
  1019.  
  1020.  
  1021.  
  1022.        $ chmod u+x file
  1023.  
  1024.  
  1025.  
  1026.  
  1027.   this sets the execute permission for the file owner. Shortcut: chmod
  1028.   +x file.
  1029.  
  1030.  
  1031.  
  1032.        $ chmod go-wx file
  1033.  
  1034.  
  1035.  
  1036.  
  1037.   this removes write and execute permission for everyone except the
  1038.   owner.
  1039.  
  1040.  
  1041.  
  1042.        $ chmod ugo+rwx file
  1043.  
  1044.  
  1045.  
  1046.  
  1047.   this gives everyone read, write, and execute permission.
  1048.  
  1049.   A shorter way to refer to permissions is with numbers: rwxr-xr-x can
  1050.   be expressed as 755 (every letter corresponds to a bit: --- is 0, --x
  1051.   is 1, -w- is 2...).
  1052.  
  1053.   For a directory, rx means that you can cd to that directory, and w
  1054.   means that you can delete a file in the directory (according to the
  1055.   file's permissions, of course), or the directory itself. All this is
  1056.   only part of the matter---RMP.
  1057.   To change a file's owner:
  1058.  
  1059.  
  1060.  
  1061.        $ chown username file
  1062.  
  1063.  
  1064.  
  1065.  
  1066.   To sum up, a table:
  1067.  
  1068.  
  1069.  
  1070.        VMS                             Linux                   Notes
  1071.        ------------------------------------------------------------------------------
  1072.  
  1073.        SET PROT=(O:RW) file.txt        $ chmod u+rw file.txt
  1074.                                        $ chmod 600 file.txt
  1075.        SET PROT=(O:RWED,W) file        $ chmod u+rwx file
  1076.                                        $ chmod 700 file
  1077.        SET PROT=(O:RWED,W:RE) file     $ chmod 755 file
  1078.        SET PROT=(O:RW,G:RW,W) file     $ chmod 660 file
  1079.        SET FILE/OWNER_UIC=JOE file     $ chown joe file
  1080.        SET DIR/OWNER_UIC=JOE [.dir]    $ chown joe dir/
  1081.  
  1082.  
  1083.  
  1084.  
  1085.  
  1086.  
  1087.   8.2.  Multitasking: Processes and Jobs
  1088.  
  1089.  
  1090.   More about running programs. There are no `batch queues' under Linux
  1091.   as you're used to; multitasking is handled very differently. Again,
  1092.   this is what the typical command line looks like:
  1093.  
  1094.  
  1095.  
  1096.        $ command -s1 -s2 ... -sn par1 par2 ... parn < input > output &
  1097.  
  1098.  
  1099.  
  1100.  
  1101.   where -s1, ..., -sn are the program switches, par1, ..., parn are the
  1102.   program parameters.
  1103.  
  1104.   Now let's see how multitasking works. Programs, running in foreground
  1105.   or background, are called `processes'.
  1106.  
  1107.  
  1108.   ╖  To launch a process in background:
  1109.  
  1110.  
  1111.        $ progname [-switches] [parameters] [< input] [> output] &
  1112.        [1] 234
  1113.  
  1114.  
  1115.  
  1116.  
  1117.   the shell tells you what the `job number' (the first digit; see below)
  1118.   and PID (Process IDentifier) of the process are. Each process is iden¡
  1119.   tified by its PID.
  1120.  
  1121.   ╖  To see how many processes there are:
  1122.  
  1123.   $ ps -ax
  1124.  
  1125.  
  1126.  
  1127.  
  1128.   This will output a list of currently running processes.
  1129.  
  1130.   ╖  To kill a process:
  1131.  
  1132.  
  1133.        $ kill <PID>
  1134.  
  1135.  
  1136.  
  1137.  
  1138.   You may need to kill a process when you don't know how to quit it the
  1139.   right way... ;-). Sometimes, a process will only be killed by one of
  1140.   the following:
  1141.  
  1142.  
  1143.        $ kill -15 <PID>
  1144.        $ kill -9 <PID>
  1145.  
  1146.  
  1147.  
  1148.  
  1149.  
  1150.   In addition to this, the shell allows you to stop or temporarily
  1151.   suspend a process, send a process to background, and bring a process
  1152.   from background to foreground. In this context, processes are called
  1153.   `jobs'.
  1154.  
  1155.  
  1156.   ╖  To see how many jobs there are:
  1157.  
  1158.  
  1159.        $ jobs
  1160.  
  1161.  
  1162.  
  1163.  
  1164.   jobs are identified by the numbers the shell gives them, not by their
  1165.   PID.
  1166.  
  1167.   ╖  To stop a process running in foreground:
  1168.  
  1169.  
  1170.        $ CTRL-C
  1171.  
  1172.  
  1173.  
  1174.  
  1175.   (it doesn't always work)
  1176.  
  1177.   ╖  To suspend a process running in foreground:
  1178.  
  1179.  
  1180.        $ CTRL-Z
  1181.  
  1182.  
  1183.  
  1184.  
  1185.   (ditto)
  1186.  
  1187.   ╖  To send a suspended process into background (it becomes a job):
  1188.  
  1189.   $ bg <job>
  1190.  
  1191.  
  1192.  
  1193.  
  1194.  
  1195.   ╖  To bring a job to foreground:
  1196.  
  1197.  
  1198.        $ fg <job>
  1199.  
  1200.  
  1201.  
  1202.  
  1203.  
  1204.   ╖  To kill a job:
  1205.  
  1206.  
  1207.        $ kill <%job>
  1208.  
  1209.  
  1210.  
  1211.  
  1212.  
  1213.  
  1214.   8.3.  Files, Revisited
  1215.  
  1216.  
  1217.   More information about files.
  1218.  
  1219.  
  1220.   ╖  stdin, stdout, stderr: under UNIX, every system component is
  1221.      treated as if it were a file. Commands and programs get their input
  1222.      from a `file' called stdin (standard input; usually, the keyboard),
  1223.      put their output on a `file' called stdout (usually, the screen),
  1224.      and error messages go to a `file' called stderr (usually, the
  1225.      screen).
  1226.  
  1227.      Using < and > you redirect input and output to a different file.
  1228.      Moreover, >> appends the output to a file instead of overwriting
  1229.      it; 2> redirects error messages (stderr); 2>&1 redirects stderr to
  1230.      stdout, while 1>&2 redirects stdout to stderr.  There's a `black
  1231.      hole' called /dev/null: everything redirected to it disappears;
  1232.  
  1233.   ╖  wildcards: '*' is almost the same. Usage: * matches all files
  1234.      except the hidden ones; .* matches all hidden files; *.* matches
  1235.      only those that have a '.' in the middle, followed by other
  1236.      characters; p*r matches both `peter' and `piper'; *c* matches both
  1237.      `picked' and `peck'.  []. Usage: [abc]* matches files starting with
  1238.      a, b, c; *[I-N,1,2,3] matches files ending with I, J, K, L, M, N,
  1239.      1, 2, 3;
  1240.  
  1241.   ╖  mv (RENAME) doesn't work for multiple files; that is, mv *.xxx
  1242.      *.yyy won't work;
  1243.  
  1244.   ╖  use cp -i and mv -i to be warned when a file is going to be
  1245.      overwritten.
  1246.  
  1247.  
  1248.  
  1249.   8.4.  Print Queues
  1250.  
  1251.  
  1252.   Your prints are queued, like under VMS. When you issue a print
  1253.   command, you may specify a printer name. Example:
  1254.  
  1255.        $ lpr file.txt          # this goes to the standard printer
  1256.        $ lpr -Plaser file.ps   # this goes to the printer named 'laser'
  1257.  
  1258.  
  1259.  
  1260.  
  1261.   To handle the print queues, you use the following commands:
  1262.  
  1263.  
  1264.  
  1265.  
  1266.        VMS                                     Linux
  1267.        ------------------------------------------------------------------------------
  1268.  
  1269.        $ PRINT file.ps                         $ lpr file.ps
  1270.        $ PRINT/QUEUE=laser file.ps             $ lpr -Plaser file.ps
  1271.        $ SHOW QUEUE                            $ lpq
  1272.        $ SHOW QUEUE/QUEUE=laser                $ lpq -Plaser
  1273.        $ STOP/QUEUE                            $ lprm <item>
  1274.  
  1275.  
  1276.  
  1277.  
  1278.  
  1279.  
  1280.   9.  Configuring
  1281.  
  1282.  
  1283.   Your sysadm has already provided you with a number of configuration
  1284.   files like .xinitrc, .bash_profile, .inputrc, and many others. The
  1285.   ones you may want to edit are:
  1286.  
  1287.  
  1288.   ╖   .bash_profile or .profile: read by the shell at login time. It's
  1289.      like LOGIN.COM;
  1290.  
  1291.   ╖   .bash_logout: read by the shell at logout. It's like LOGOUT.COM;
  1292.  
  1293.   ╖   .bashrc: read by non--login shells.
  1294.  
  1295.   ╖   .inputrc: this file customises the key bindings and the behaviour
  1296.      of the shell.
  1297.  
  1298.   To give you an example, I'll include my .bash_profile (abridged):
  1299.  
  1300.  
  1301.  
  1302.  
  1303.  
  1304.  
  1305.  
  1306.  
  1307.  
  1308.  
  1309.  
  1310.  
  1311.  
  1312.  
  1313.  
  1314.  
  1315.  
  1316.  
  1317.  
  1318.  
  1319.  
  1320.  
  1321.   ______________________________________________________________________
  1322.   # $HOME/.bash_profile
  1323.  
  1324.   # don't redefine the path if not necessary
  1325.   echo $PATH | grep $LOGNAME > /dev/null
  1326.   if [ $? != 0 ]
  1327.   then
  1328.     export PATH="$PATH:/home/$LOGNAME/bin"  # add my dir to the PATH
  1329.   fi
  1330.  
  1331.   export PS1='LOGNAME:\w\$ '
  1332.   export PS2='Continued...>'
  1333.  
  1334.   # aliases
  1335.  
  1336.   alias bin="cd ~/bin" ; alias cp="cp -i" ; alias d="dir"
  1337.   alias del="delete" ; alias dir="/bin/ls $LS_OPTIONS --format=vertical"
  1338.   alias ed="jed" ; alias mv='mv -i'
  1339.   alias u="cd .." ; alias undel="undelete"
  1340.  
  1341.   # A few useful functions
  1342.  
  1343.   inst() # Install a .tar.gz archive in current directory.
  1344.   {
  1345.     gzip -dc $1 | tar xvf -
  1346.   }
  1347.   cz() # List the contents of a .zip archive.
  1348.   {
  1349.     unzip -l $*
  1350.   }
  1351.   ctgz() # List the contents of a .tar.gz archive.
  1352.   {
  1353.     for file in $* ; do
  1354.       gzip -dc ${file} | tar tf -
  1355.     done
  1356.   }
  1357.   tgz() # Create a .tgz archive a la zip.
  1358.   {
  1359.     name=$1 ; tar -cvf $1 ; shift
  1360.     tar -rf ${name} $* ; gzip -S .tgz ${name}
  1361.   }
  1362.   ______________________________________________________________________
  1363.  
  1364.  
  1365.  
  1366.   And this is my .inputrc:
  1367.  
  1368.  
  1369.  
  1370.  
  1371.  
  1372.  
  1373.  
  1374.  
  1375.  
  1376.  
  1377.  
  1378.  
  1379.  
  1380.  
  1381.  
  1382.  
  1383.  
  1384.  
  1385.  
  1386.  
  1387.   ______________________________________________________________________
  1388.   # $HOME/.inputrc
  1389.   # Last modified: 16 January 1997.
  1390.   #
  1391.   # This file is read by bash and defines key bindings to be used by the shell;
  1392.   # what follows fixes the keys END, HOME, and DELETE, plus accented letters.
  1393.   # For more information, man readline.
  1394.  
  1395.   "\e[1~": beginning-of-line
  1396.   "\e[3~": delete-char
  1397.   "\e[4~": end-of-line
  1398.  
  1399.   set bell-style visible
  1400.   set meta-flag On
  1401.   set convert-meta Off
  1402.   set output-meta On
  1403.   set horizontal-scroll-mode On
  1404.   set show-all-if-ambiguous On
  1405.  
  1406.   # (F1 .. F5) are "\e[[A" ... "\e[[E"
  1407.  
  1408.   "\e[[A": "info "
  1409.   ______________________________________________________________________
  1410.  
  1411.  
  1412.  
  1413.  
  1414.  
  1415.   10.  Useful Programs
  1416.  
  1417.  
  1418.  
  1419.   10.1.  Browsing Files: less
  1420.  
  1421.  
  1422.   You'll use this file browser every day, so I'll give you a couple of
  1423.   tips to use it at best. First of all, ask your sysadm to configure
  1424.   less so as it can display not only plain text files, but also
  1425.   compressed files, archives, and so on.
  1426.  
  1427.   The main advantage of less over TYPE is that you can browse files in
  1428.   both directions. It also accepts several commands that are issued
  1429.   pressing a key. The most useful are:
  1430.  
  1431.  
  1432.   ╖  first of all, press q to leave the browser;
  1433.  
  1434.   ╖  h gives you extensive help;
  1435.  
  1436.   ╖  g to go to beginning of file, G to the end, number+g to go to line
  1437.      `number' (e.g. 125g), number+% to move to that percentage of the
  1438.      file;
  1439.  
  1440.   ╖  /pattern searches forwards for `pattern'; n searches forwards for
  1441.      the next match; ?pattern and N search backwards;
  1442.  
  1443.   ╖  m+letter marks current position (e.g. ma); '+letter go to the
  1444.      marked position.
  1445.  
  1446.   ╖  :e examines a new file;
  1447.  
  1448.   ╖  !command executes the shell command.
  1449.  
  1450.  
  1451.  
  1452.  
  1453.   10.2.  RCS in a Nutshell
  1454.  
  1455.  
  1456.   The lack of version numbers in files can be easily overcome by using
  1457.   RCS (Revision Control System). This allows you to maintain several
  1458.   versions of the same file, and offers many more advantages. I'll only
  1459.   explain the very basics of this powerful version control system.
  1460.  
  1461.   The most important commands are ci and co. The first (``check in'') is
  1462.   used to commit the changes you have done to your file, and create a
  1463.   new version. The second (``check out'') is used to obtain a working
  1464.   copy of your file from the RCS system, either to modify it or simply
  1465.   use it for browsing, printing, or whatever.
  1466.  
  1467.   Let's see an example. First of all you create an initial revision of
  1468.   your file, using your favourite editor. Let's suppose that the file
  1469.   you'll have under RCS control is called project.tex. Follow these
  1470.   steps:
  1471.  
  1472.  
  1473.   ╖  make a subdirectory called RCS/ in the directory containing
  1474.      project.tex. RCS/ will contain the revision control file;
  1475.  
  1476.   ╖  to put project.tex under RCS control, issue the command
  1477.  
  1478.  
  1479.        $ ci project.tex
  1480.        RCS/project.tex,v  <-- project.tex
  1481.        enter description, terminated with a single '.' or end of file:
  1482.        NOTE: This is NOT the log message!
  1483.        >>
  1484.  
  1485.  
  1486.  
  1487.  
  1488.  
  1489.   ╖  you will write a line or more containing a description of the
  1490.      contents of your file. End it with a line containing a '.' by
  1491.      itself, and you'll see
  1492.  
  1493.  
  1494.        initial revision: 1.1
  1495.        done
  1496.  
  1497.  
  1498.  
  1499.  
  1500.  
  1501.   Now the file project.tex has been taken over by RCS.
  1502.  
  1503.  
  1504.   10.2.1.  Using the latest version
  1505.  
  1506.  
  1507.   Whenever you want to use, but not modify, the latest version of
  1508.   project.tex, you issue the command
  1509.  
  1510.  
  1511.        $ co project.tex
  1512.        RCS/project.tex,v  --> project.tex
  1513.        revision 1.1
  1514.        done
  1515.  
  1516.  
  1517.  
  1518.  
  1519.   This extracts the latest version (read only) of your file. Now you can
  1520.   browse it, or compile it with tex, but you can't modify it.
  1521.  
  1522.  
  1523.  
  1524.   10.2.2.  Creating a new version
  1525.  
  1526.  
  1527.   When you want to modify your file, you must obtain a ``lock'' on it.
  1528.   This means that RCS knows that you're about to make a newer version.
  1529.   In this case, you use the command
  1530.  
  1531.  
  1532.  
  1533.        $ co project.tex
  1534.        RCS/project.tex,v  --> project.tex
  1535.        revision 1.1 (locked)
  1536.        done
  1537.  
  1538.  
  1539.  
  1540.  
  1541.   You now have a working copy you can modify with your editor. When
  1542.   you're done editing it, you check it in again to commit the changes:
  1543.  
  1544.  
  1545.  
  1546.        $ ci project.tex
  1547.        RCS/project.tex,v  <-- project.tex
  1548.        new revision 1.2; previous revision: 1.1
  1549.        enter log message, terminated with a single '.' or end of file:
  1550.        >> (enter your description here)
  1551.        >> .
  1552.        done
  1553.  
  1554.  
  1555.  
  1556.  
  1557.   If you want to change the version number, type ci -f2.0 project.tex.
  1558.  
  1559.  
  1560.   10.2.3.  Comparing versions
  1561.  
  1562.  
  1563.   If you want to see the history of the changes in project.tex, issue
  1564.  
  1565.  
  1566.        $ rlog project.tex
  1567.  
  1568.  
  1569.  
  1570.  
  1571.  
  1572.   10.2.4.  Using an old version
  1573.  
  1574.  
  1575.   To extract an older version of your file (say, version 1.2 when you're
  1576.   working on 1.6), issue
  1577.  
  1578.  
  1579.        $ co -r1.2 project.tex
  1580.  
  1581.  
  1582.  
  1583.  
  1584.  
  1585.   Be aware that this overwrites your existing working file, if you have
  1586.   one.  You may do:
  1587.  
  1588.  
  1589.        $ co -r1.2 -p project.tex > project.tex.1.2
  1590.  
  1591.  
  1592.  
  1593.  
  1594.  
  1595.  
  1596.   10.3.  Archiving: tar & gzip
  1597.  
  1598.  
  1599.   Under UNIX there are some widely used applications to archive and
  1600.   compress files. tar is used to make archives, that is collections of
  1601.   files. To make a new archive:
  1602.  
  1603.  
  1604.  
  1605.        $ tar -cvf <archive_name.tar> <file> [file...]
  1606.  
  1607.  
  1608.  
  1609.  
  1610.   To extract files from an archive:
  1611.  
  1612.  
  1613.  
  1614.        $ tar -xpvf <archive_name.tar> [file...]
  1615.  
  1616.  
  1617.  
  1618.  
  1619.   To list the contents of an archive:
  1620.  
  1621.  
  1622.  
  1623.        $ tar -tf <archive_name.tar> | less
  1624.  
  1625.  
  1626.  
  1627.  
  1628.   Files can be compressed to save disk space using compress, which is
  1629.   obsolete and shouldn't be used any more, or gzip:
  1630.  
  1631.  
  1632.  
  1633.        $ compress <file>
  1634.        $ gzip <file>
  1635.  
  1636.  
  1637.  
  1638.  
  1639.   that creates a compressed file with extension .Z (compress) or .gz
  1640.   (gzip). These programs don't make archives, but compress files
  1641.   individually. To decompress, use:
  1642.  
  1643.  
  1644.  
  1645.        $ compress -d <file.Z>
  1646.        $ gzip -d <file.gz>
  1647.  
  1648.  
  1649.  
  1650.  
  1651.   RMP.
  1652.  
  1653.   The unarj, zip and unzip utilities are also available. Files with
  1654.   extension .tar.gz or .tgz (archived with tar, then compressed with
  1655.   gzip) are very common in the UNIX world. Here's how to list the
  1656.   contents of a .tar.gz archive:
  1657.  
  1658.  
  1659.  
  1660.        $ gzip -dc <file.tar.gz> | tar tf - | less
  1661.  
  1662.  
  1663.  
  1664.  
  1665.   To extract the files from a .tar.gz archive:
  1666.  
  1667.  
  1668.  
  1669.        $ gzip -dc <file.tar.gz> | tar xvf -
  1670.  
  1671.  
  1672.  
  1673.  
  1674.  
  1675.  
  1676.   11.  Real Life Examples
  1677.  
  1678.  
  1679.   UNIX' core idea is that there are many simple commands that can linked
  1680.   together via piping and redirection to accomplish even really complex
  1681.   tasks.  Look at the following examples; I'll only explain the most
  1682.   complex ones, for the others, please study the above sections and the
  1683.   man pages.
  1684.  
  1685.   Problem: ls is too quick and the file names fly away.
  1686.  
  1687.   Solution:
  1688.  
  1689.  
  1690.  
  1691.        $ ls | less
  1692.  
  1693.  
  1694.  
  1695.  
  1696.   Problem: I have a file containing a list of words. I want to sort it
  1697.   in reverse order and print it.
  1698.  
  1699.   Solution:
  1700.  
  1701.  
  1702.  
  1703.        $ cat myfile.txt | sort -r | lpr
  1704.  
  1705.  
  1706.  
  1707.  
  1708.   Problem: my datafile has some repeated lines! How do I get rid of
  1709.   them?
  1710.  
  1711.   Solution:
  1712.  
  1713.  
  1714.  
  1715.        $ sort datafile.dat | uniq > newfile.dat
  1716.  
  1717.   Problem: I have a file called 'mypaper.txt' or 'mypaper.tex' or some
  1718.   such somewhere, but I don't remember where I put it. How do I find it?
  1719.  
  1720.   Solution:
  1721.  
  1722.  
  1723.  
  1724.        $ find ~ -name "mypaper*"
  1725.  
  1726.  
  1727.  
  1728.  
  1729.   Explanation: find is a very useful command that lists all the files in
  1730.   a directory tree (starting from ~ in this case). Its output can be
  1731.   filtered to meet several criteria, such as -name.
  1732.  
  1733.   Problem: I have a text file containing the word 'entropy' in this
  1734.   directory, is there anything like SEARCH?
  1735.  
  1736.   Solution: yes, try
  1737.  
  1738.  
  1739.  
  1740.        $ grep -l 'entropy' *
  1741.  
  1742.  
  1743.  
  1744.  
  1745.   Problem: somewhere I have text files containing the word 'entropy',
  1746.   I'd like to know which and where they are. Under VMS I'd use search
  1747.   entropy [...]*.*.*, but grep can't recurse subdirectories. Now what?
  1748.  
  1749.   Solution:
  1750.  
  1751.  
  1752.  
  1753.        $ find . -exec grep -l "entropy" {} \; 2> /dev/null
  1754.  
  1755.  
  1756.  
  1757.  
  1758.   Explanation: find . outputs all the file names starting from the
  1759.   current directory, -exec grep -l "entropy" is an action to be
  1760.   performed on each file (represented by {}), \ terminates the command.
  1761.   If you think this syntax is awful, you're right.
  1762.  
  1763.   In alternative, write the following script:
  1764.  
  1765.  
  1766.   ______________________________________________________________________
  1767.   #!/bin/sh
  1768.   # rgrep: recursive grep
  1769.   if [ $# != 3 ]
  1770.   then
  1771.     echo "Usage: rgrep --switches 'pattern' 'directory'"
  1772.     exit 1
  1773.   fi
  1774.   find $3 -name "*" -exec grep $1 $2 {} \; 2> /dev/null
  1775.   ______________________________________________________________________
  1776.  
  1777.  
  1778.  
  1779.   Explanation: grep works like search, and combining it with find we get
  1780.   the best of both worlds.
  1781.  
  1782.  
  1783.   Problem: I have a data file that has two header lines, then every line
  1784.   has 'n' data, not necessarily equally spaced. I want the 2nd and 5th
  1785.   data of each line. Shall I write a Fortran program...?
  1786.  
  1787.   Solution: nope. This is quicker:
  1788.  
  1789.  
  1790.  
  1791.        $ awk 'NL > 2 {print $2, "\t", $5}' datafile.dat > newfile.dat
  1792.  
  1793.  
  1794.  
  1795.  
  1796.   Explanation: the command awk is actually a programming language: for
  1797.   each line starting from the third in datafile.dat, print out the
  1798.   second and fifth field, separated by a tab. Learn some awk---it saves
  1799.   a lot of time.
  1800.  
  1801.   Problem: I've downloaded an FTP site's ls-lR.gz to check its contents.
  1802.   For each subdirectory, it contains a line that reads "total xxxx",
  1803.   where xxxx is size in kbytes of the dir contents. I'd like to get the
  1804.   grand total of all these xxxx values.
  1805.  
  1806.   Solution:
  1807.  
  1808.  
  1809.  
  1810.        zcat ls-lR.gz | awk ' $1 == "total" { i += $2 } END {print i}'
  1811.  
  1812.  
  1813.  
  1814.  
  1815.   Explanation: zcat outputs the contents of the .gz file and pipes to
  1816.   awk, whose man page you're kindly requested to read ;-)
  1817.  
  1818.   Problem: I've written a Fortran program, myprog, to calculate a
  1819.   parameter from a data file. I'd like to run it on hundreds of data
  1820.   files and have a list of the results, but it's a nuisance to ask each
  1821.   time for the file name. Under VMS I'd write a lengthy command file,
  1822.   and under Linux?
  1823.  
  1824.   Solution: a very short script. Make your program look for the data
  1825.   file 'mydata.dat' and print the result on the screen (stdout), then
  1826.   write the following script:
  1827.  
  1828.  
  1829.   ______________________________________________________________________
  1830.   #!/bin/sh
  1831.   # myprog.sh: run the same command on many different files
  1832.   # usage: myprog.sh *.dat
  1833.   for file in $*  # for all parameters (e.g. *.dat)
  1834.   do
  1835.     # append the file name to result.dat
  1836.     echo -n "${file}:    " >> results.dat
  1837.     # copy current argument to mydata.dat, run myprog
  1838.     # and append the output to results.dat
  1839.     cp ${file} mydata.dat ; myprog >> results.dat
  1840.   done
  1841.   ______________________________________________________________________
  1842.  
  1843.  
  1844.  
  1845.   Problem: I want to replace `geology' with `geophysics' in all my text
  1846.   files. Shall I edit them all manually?
  1847.  
  1848.  
  1849.   Solution: nope. Write this shell script:
  1850.  
  1851.  
  1852.   ______________________________________________________________________
  1853.   #!/bin/sh
  1854.   # replace $1 with $2 in $*
  1855.   # usage: replace "old-pattern" "new-pattern" file [file...]
  1856.   OLD=$1          # first parameter of the script
  1857.   NEW=$2          # second parameter
  1858.   shift ; shift   # discard first two parameters: the next are the file names
  1859.   for file in $*  # for all files given as parameters
  1860.   do
  1861.   # replace every occurrence of OLD with NEW, save on a temporary file
  1862.     sed "s/$OLD/$NEW/g" ${file} > ${file}.new
  1863.   # rename the temporary file as the original file
  1864.     /bin/mv ${file}.new ${file}
  1865.   done
  1866.   ______________________________________________________________________
  1867.  
  1868.  
  1869.  
  1870.   Problem: I have some data files, I don't know their length and have to
  1871.   remove their last but one and last but two lines. Er... manually?
  1872.  
  1873.   Solution: no, of course. Write this script:
  1874.  
  1875.  
  1876.   ______________________________________________________________________
  1877.   #!/bin/sh
  1878.   # prune.sh: removes n-1th and n-2th lines from files
  1879.   # usage: prune.sh file [file...]
  1880.   for file in $*   # for every parameter
  1881.   do
  1882.     LINES=`wc -l $file | awk '{print $1}'`  # number of lines in file
  1883.     LINES=`expr $LINES - 3`                 # LINES = LINES - 3
  1884.     head -n $LINES $file > $file.new        # output first LINES lines
  1885.     tail -n 1 $file >> $file.new            # append last line
  1886.   done
  1887.   ______________________________________________________________________
  1888.  
  1889.  
  1890.  
  1891.   I hope these examples whetted your appetite...
  1892.  
  1893.  
  1894.  
  1895.   12.  Tips You Can't Do Without
  1896.  
  1897.  
  1898.  
  1899.   ╖  Command completion: pressing <TAB> when issuing a command will
  1900.      complete the command line for you. Example: you have to type less
  1901.      this_is_a_long_name; typing in less thi<TAB> will suffice. (If you
  1902.      have other files that start with the same characters, supply enough
  1903.      characters to resolve any ambiguity.)
  1904.  
  1905.   ╖  Back-scrolling: pressing SHIFT--PAG UP (the grey key) allows you to
  1906.      backscroll a few pages, depending on your PC's video memory.
  1907.  
  1908.   ╖  Resetting the screen: if you happen to more or cat a binary file,
  1909.      your screen may end up full of garbage. To fix things, blind type
  1910.      reset or this sequence of characters: echo CTRL-V ESC c RETURN.
  1911.  
  1912.   ╖  Pasting text: in console, see below; in X, click and drag to select
  1913.      the text in an xterm window, then click the middle button (or the
  1914.      two buttons together if you have a two-button mouse) to paste.
  1915.   ╖  Using the mouse: ask your sysadm to install gpm, a mouse driver for
  1916.      the console. Click and drag to select text, then right click to
  1917.      paste the selected text. It works across different VCs.
  1918.  
  1919.  
  1920.  
  1921.   13.  The End
  1922.  
  1923.  
  1924.  
  1925.   13.1.  Copyright
  1926.  
  1927.  
  1928.   Unless otherwise stated, Linux HOWTO documents are copyrighted by
  1929.   their respective authors. Linux HOWTO documents may be reproduced and
  1930.   distributed in whole or in part, in any medium physical or electronic,
  1931.   as long as this copyright notice is retained on all copies. Commercial
  1932.   redistribution is allowed and encouraged; however, the author would
  1933.   like to be notified of any such distributions.
  1934.  
  1935.   All translations, derivative works, or aggregate works incorporating
  1936.   any Linux HOWTO documents must be covered under this copyright notice.
  1937.   That is, you may not produce a derivative work from a HOWTO and impose
  1938.   additional restrictions on its distribution. Exceptions to these rules
  1939.   may be granted under certain conditions; please contact the Linux
  1940.   HOWTO coordinator at the address given below.
  1941.  
  1942.   In short, we wish to promote dissemination of this information through
  1943.   as many channels as possible. However, we do wish to retain copyright
  1944.   on the HOWTO documents, and would like to be notified of any plans to
  1945.   redistribute the HOWTOs.
  1946.  
  1947.   If you have questions, please contact Tim Bynum, the Linux HOWTO
  1948.   coordinator, at linux-howto@sunsite.unc.edu via email.
  1949.  
  1950.  
  1951.  
  1952.   14.  Disclaimer
  1953.  
  1954.  
  1955.   This work was written following the experience we had at the Settore
  1956.   di Geofisica of Bologna University (Italy), where a VAX 4000 is being
  1957.   superseded and replaced by Linux-based Pentium PCs. Most of my
  1958.   colleagues are VMS users, and some of them have switched to Linux.
  1959.  
  1960.   ``From VMS to Linux HOWTO'' was written by Guido Gonzato,
  1961.   guido@ibogfs.cineca.it, 1997. Many thanks to my colleagues and friends
  1962.   who helped me define the needs and habits of the average VMS user,
  1963.   especially to Dr. Warner Marzocchi.
  1964.  
  1965.   Please help me improve this HOWTO. I'm not a VMS expert and never will
  1966.   be, so your suggestions and bug reports are more than welcome.
  1967.  
  1968.   Enjoy,
  1969.  
  1970.   Guido =8-)
  1971.  
  1972.  
  1973.  
  1974.  
  1975.  
  1976.  
  1977.  
  1978.  
  1979.  
  1980.  
  1981.