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

  1.   From DOS/Windows to Linux HOWTO
  2.   By Guido Gonzato, guido@ibogfs.cineca.it
  3.   v1.3.0, 15 April 1998
  4.  
  5.   This HOWTO is dedicated to all the (soon to be former?) DOS and Win¡
  6.   dows users who have decided to switch to Linux, the free UNIX clone.
  7.   The purpose of this document is to help the reader translate his or
  8.   her knowledge of DOS and Windows into the Linux environment, as well
  9.   as providing hints on exchanging files and resources between the two
  10.   OSes.
  11.   ______________________________________________________________________
  12.  
  13.   Table of Contents
  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 Is Linux Right for You?
  70.      1.2 It Is. Tell Me More
  71.         1.2.1 Introductory Concepts
  72.         1.2.2 Getting Help
  73.      1.3 Conventions
  74.  
  75.   2. For the Impatient
  76.  
  77.   3. Files and Programs
  78.  
  79.      3.1 Files: Preliminary Notions
  80.      3.2 Symbolic Links
  81.      3.3 Permissions and Ownership
  82.      3.4 Files: Translating Commands
  83.         3.4.1 Examples
  84.      3.5 Running Programs: Multitasking and Sessions
  85.      3.6 Running Programs on Remote Computers
  86.  
  87.   4. Using Directories
  88.  
  89.      4.1 Directories: Preliminary Notions
  90.      4.2 Directories Permissions
  91.      4.3 Directories: Translating Commands
  92.         4.3.1 Examples
  93.  
  94.   5. Floppies, Hard Disks, and the Like
  95.  
  96.      5.1 Managing Devices the DOS Way
  97.      5.2 Managing Devices the UNIX Way
  98.      5.3 Backing Up
  99.  
  100.   6. What About Windows?
  101.  
  102.   7. Tailoring the System
  103.  
  104.      7.1 System Initialisation Files
  105.      7.2 Program Initialisation Files
  106.  
  107.   8. A Bit of Programming
  108.  
  109.      8.1 Shell Scripts: .BAT Files on Steroids
  110.      8.2 C for Yourself
  111.  
  112.   9. The Remaining 1%
  113.  
  114.      9.1 Using tar & gzip
  115.      9.2 Installing Applications
  116.      9.3 Tips You Can't Do Without
  117.      9.4 Where to Find Applications
  118.      9.5 A Few Things You Couldn't Do
  119.      9.6 Common Extensions and Related Programs
  120.      9.7 Converting Files
  121.  
  122.   10. The End, for Now
  123.  
  124.      10.1 Copyright
  125.      10.2 Disclaimer
  126.  
  127.  
  128.   ______________________________________________________________________
  129.  
  130.  
  131.  
  132.  
  133.   1.  Introduction
  134.  
  135.  
  136.  
  137.   1.1.  Is Linux Right for You?
  138.  
  139.  
  140.   You want to switch from DOS/Windows to Linux? Good idea: Linux is
  141.   technically superior to DOS, Windows 95 and even Windows NT. But
  142.   beware: it might not be useful for you if you are not the right type
  143.   of user. In fact, DOS and Windows are mostly employed for games and
  144.   office productivity, while Linux gives its best at networking,
  145.   development, and scientific computing.  Linux is incredibly powerful,
  146.   but learning how to harness that power takes time. Thus, if mostly
  147.   need commercial sw, or if you don't feel like learning new commands
  148.   and concepts, you had better look elsewhere.
  149.  
  150.   Work is underway to make Linux simpler to use, but don't expect to be
  151.   proficient with it unless you read a lot of documentation and use it
  152.   at least for a few months. Linux won't give you instant results. In
  153.   spite of these warnings, I'm 100% confident that if you are the right
  154.   user type you'll find in Linux your computer Nirvana, and never want
  155.   to use DOS or Windows again. By the way, Linux + DOS/Win can coexist
  156.   happily on the same machine.
  157.  
  158.   Prerequisites for this howto: I'll assume that
  159.  
  160.  
  161.   ╖  you know the basic DOS commands and concepts;
  162.  
  163.   ╖  Linux, possibly with X Window System, is properly installed on your
  164.      PC;
  165.  
  166.   ╖  your shell---the equivalent of COMMAND.COM---is bash.
  167.  
  168.   Unless specified, all information in this work is aimed at bad ol'
  169.   DOS.  There is information about Windows here and there, but bear in
  170.   mind that Windows and Linux are totally different, unlike DOS that is
  171.   sort of a UNIX poor relation. Please also note that this work is
  172.   neither a complete primer nor a configuration guide!
  173.  
  174.  
  175.  
  176.   1.2.  It Is. Tell Me More
  177.  
  178.  
  179.   You installed Linux and the programs you needed on the PC. You gave
  180.   yourself an account (if not, type adduser now!) and Linux is running.
  181.   You've just entered your name and password, and now you are looking at
  182.   the screen thinking: ``Well, now what?''
  183.  
  184.   Now, don't despair. You're almost ready to do the same things you used
  185.   to do with DOS/Win, and many more. If you were running DOS/Win instead
  186.   of Linux, you would be doing some of the following tasks:
  187.  
  188.  
  189.   ╖  running programs and creating, copying, viewing, deleting,
  190.      printing, renaming files;
  191.  
  192.   ╖  CD'ing, MD'ing, RD'ing, and DIR'ring your directories;
  193.  
  194.   ╖  formatting floppies and copying files from/to them;
  195.  
  196.   ╖  tailoring the system;
  197.  
  198.  
  199.   ╖  writing .BAT files and programs in your favourite language;
  200.  
  201.   ╖  the remaining 1%.
  202.  
  203.   You'll be glad to know that these tasks can be accomplished under
  204.   Linux in a fashion similar to DOS. Under DOS, the average user uses
  205.   very few of the 100+ commands available: the same, up to a point,
  206.   applies to Linux.
  207.  
  208.  
  209.  
  210.   1.2.1.  Introductory Concepts
  211.  
  212.  
  213.   The best way to learn something new is to get your feet wet. You are
  214.   strongly encouraged to experiment and play with Linux: you can't
  215.   damage the system that way. A few points:
  216.  
  217.  
  218.   ╖  first of all, how to quit Linux safely. If you see a text mode
  219.      screen, press <CTRL-ALT-DEL>, wait for the system to reboot, then
  220.      switch off the PC. If you are working under X Window System, press
  221.      <CTRL-ALT-BACKSPACE> first, then <CTRL-ALT-DEL>. Never switch off
  222.      or reset the PC directly: this could damage the file system;
  223.  
  224.   ╖  unlike DOS, Linux has built-in security mechanisms. Files and
  225.      directories have permissions associated to them; as a result, some
  226.      cannot be accessed by the normal user; (see Section ``Permissions
  227.      and Ownership''). DOS, on the contrary, will let you wipe out the
  228.      entire contents of your hard disk;
  229.  
  230.   ╖  there's a special user called ``root'': the system administrator,
  231.      with full power of life and death on the machine.  If you work on
  232.      your own PC, you'll be root as well. Working as root is dangerous:
  233.      any mistake can seriously damage or destroy the system just like
  234.      with DOS/Win. Don't work as root unless absolutely necessary;
  235.  
  236.   ╖  much of the complexity of Linux comes from its extreme
  237.      configurability: virtually every feature and every application can
  238.      be tailored through one or more configuration files. Complexity is
  239.      the price to pay for power;
  240.  
  241.   ╖  redirection and piping are a side DOS feature, a very inportant one
  242.      and much more powerful under Linux. Simple commands can be strung
  243.      together to accomplish complex tasks. I strongly suggest that you
  244.      learn how to use them.
  245.  
  246.  
  247.  
  248.   1.2.2.  Getting Help
  249.  
  250.  
  251.   There are many ways to get help with Linux. The most important are:
  252.  
  253.  
  254.   ╖  reading the documentation---I mean it. Although the HOWTO you are
  255.      reading may serve as an introduction to Linux, there are several
  256.      books that you really should read: Matt Welsh's ``Linux
  257.      Installation and Getting Started'' (
  258.      <http://sunsite.unc.edu/mdw/LDP/gs/gs.html> ), Larry Greenfield's
  259.      ``Linux User Guide'' (
  260.      <ftp://sunsite.unc.edu/pub/Linux/docs/linux-doc-project/users-
  261.      guide>), and the Linux FAQ ( <http://sunsite.unc.edu/mdw/FAQ/Linux-
  262.      FAQ.html>).  Feel a guilty conscience until you have read at least
  263.      one of them;
  264.  
  265.   ╖  the documentation of the packages installed on the machine is often
  266.      found in subdirectories under /usr/doc/;
  267.  
  268.   ╖  to get some help about the ``internal commands'' of the shell, type
  269.      help or, better, man bash or info bash;
  270.  
  271.   ╖  to get help on a command, type man command that invokes the manual
  272.      (``man'') page pertinent to command. Alternatively, type info
  273.      command that invokes, if available, the info page pertinent to
  274.      command. Info is a hypertext-based documentation system, perhaps
  275.      not intuitive to use at first. Finally, you may try apropos command
  276.      or whatis command. With all of these commands, press `q' to exit.
  277.  
  278.  
  279.  
  280.   1.3.  Conventions
  281.  
  282.  
  283.   Throughout this work, examples will often follow the following format:
  284.   <...> is a required argument, while [...] an optional one.  Example:
  285.  
  286.  
  287.  
  288.        $ tar -tf <file.tar> [> redir_file]
  289.  
  290.  
  291.  
  292.  
  293.   file.tar must be indicated, but redirection to redir_file is optional.
  294.  
  295.   ``RMP'' means ``please Read the Man Pages for further information''.
  296.   I can't stress enough how important reading the documentation is.
  297.  
  298.   When the prompt of a command example is `#', the command can only be
  299.   performed by root.
  300.  
  301.  
  302.  
  303.   2.  For the Impatient
  304.  
  305.  
  306.   Want to strike out? Have a look at this table:
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.   DOS                     Linux                   Notes
  332.   ------------------------------------------------------------------------------
  333.  
  334.   ATTRIB (+-)attr file    chmod <mode> file       completely different
  335.   BACKUP                  tar -Mcvf device dir/   ditto
  336.   CD dirname\             cd dirname/             almost the same syntax
  337.   COPY file1 file2        cp file1 file2          ditto
  338.   DEL file                rm file                 beware - no undelete
  339.   DELTREE dirname         rm -R dirname/          ditto
  340.   DIR                     ls                      not exactly the same syntax
  341.   DIR file /S             find . -name file       completely different
  342.   EDIT file               vi file                 I think you won't like it
  343.                           jstar file              feels like dos' edit
  344.   FORMAT                  fdformat,
  345.                           mount, umount           quite different syntax
  346.   HELP command            man command,            same philosophy
  347.                           info command
  348.   MD dirname              mkdir dirname/          almost the same syntax
  349.   MOVE file1 file2        mv file1 file2          ditto
  350.   NUL                     /dev/null               ditto
  351.   PRINT file              lpr file                ditto
  352.   PRN                     /dev/lp0,
  353.                           /dev/lp1                ditto
  354.   RD dirname              rmdir dirname/          almost the same syntax
  355.   REN file1 file2         mv file1 file2          not for multiple files
  356.   RESTORE                 tar -Mxpvf device       different syntax
  357.   TYPE file               less file               much better
  358.   WIN                     startx                  poles apart!
  359.  
  360.  
  361.  
  362.  
  363.   If you need more than a table of commands, please refer to the
  364.   following sections.
  365.  
  366.  
  367.  
  368.   3.  Files and Programs
  369.  
  370.  
  371.  
  372.  
  373.   3.1.  Files: Preliminary Notions
  374.  
  375.  
  376.   Linux has a structure of directories and files very similar to
  377.   DOS/Win's.  Files have filenames that obey special rules, are stored
  378.   in directories, some are executable, and among these most have command
  379.   switches. Moreover, you can use wildcard characters, redirection, and
  380.   piping. There are only a few minor differences:
  381.  
  382.  
  383.   ╖  under DOS, file names are in the so-called 8.3 form; e.g.
  384.      NOTENOUG.TXT. Under Linux we can do better. If you installed Linux
  385.      using a file system like ext2 or umsdos, you can use longer
  386.      filenames (up to 255 characters), and with more than one dot: for
  387.      example, This_is.a.VERY_long.filename. Please note that I used both
  388.      upper and lower case characters: in fact...
  389.  
  390.   ╖  upper and lower case characters in file names or commands are
  391.      different. Therefore, FILENAME.tar.gz and filename.tar.gz are two
  392.      different files. ls is a command, LS is a mistake;
  393.  
  394.   ╖  Windows 95 users, beware when using long file names under Linux.
  395.      If a file name contains spaces (not recommended but possible), you
  396.      must enclose the file name in double quotes whenever you refer to
  397.      it. For example:
  398.  
  399.  
  400.  
  401.        $ # the following command makes a directory called "My old files"
  402.        $ mkdir "My old files"
  403.        $ ls
  404.        My old files    bin     tmp
  405.  
  406.  
  407.  
  408.  
  409.  
  410.   Further, some characters shouldn't be used: some are !*$&.
  411.  
  412.   ╖  there are no compulsory extensions like .COM and .EXE for programs,
  413.      or .BAT for batch files. Executable files are marked by an asterisk
  414.      `*' at the end of their name when you issue the ls -F command. For
  415.      example:
  416.  
  417.  
  418.  
  419.        $ ls -F
  420.        I_am_a_dir/   cindy.jpg    cjpg*   letter_to_Joe    my_1st_script*  old~
  421.  
  422.  
  423.  
  424.  
  425.  
  426.   The files cjpg* and my_1st_script* are executables, that is ``pro¡
  427.   grams''. Under DOS, backup files end in .BAK, while under Linux they
  428.   end with a tilde `~'. Further, a file whose name starts with a dot is
  429.   considered as hidden. Example: the file .I.am.a.hidden.file won't show
  430.   up after the ls command;
  431.  
  432.   ╖  DOS program switches are obtained with /switch, Linux switches with
  433.      -switch or --switch. Example: dir /s becomes ls -R. Note that many
  434.      DOS programs, like PKZIP or ARJ, use UNIX-style switches.
  435.  
  436.   You can now jump to Section ``Translating Commands from DOS to
  437.   Linux'', but if I were you I'd read on.
  438.  
  439.  
  440.  
  441.   3.2.  Symbolic Links
  442.  
  443.  
  444.   UNIX has a type of file that doesn't exist under DOS: the symbolic
  445.   link.  This can be thought of as a pointer to a file or to a
  446.   directory, and can be used instead of the file or directory it points
  447.   to; it's similar to Windows 95 shortcuts. Examples of symbolic links
  448.   are /usr/X11, which points to /usr/X11R6; /dev/modem, which points to
  449.   either /dev/cua0 or /dev/cua1.
  450.  
  451.   To make a symbolic link:
  452.  
  453.  
  454.  
  455.        $ ln -s <file_or_dir> <linkname>
  456.  
  457.  
  458.  
  459.  
  460.   Example:
  461.  
  462.  
  463.        $ ln -s /usr/doc/g77/DOC g77manual.txt
  464.  
  465.  
  466.  
  467.  
  468.   Now you can refer to g77manual.txt instead of /usr/doc/g77/DOC.  Links
  469.   appear like this in directory listings:
  470.  
  471.  
  472.  
  473.        $ ls -F
  474.        g77manual.txt@
  475.        $ ls -l
  476.        (various things...)           g77manual.txt -> /usr/doc/g77/DOC
  477.  
  478.  
  479.  
  480.  
  481.  
  482.  
  483.   3.3.  Permissions and Ownership
  484.  
  485.  
  486.   DOS files and directories have the following attributes: A (archive),
  487.   H (hidden), R (read-only), and S (system). Only H and R make sense
  488.   under Linux: hidden files start with a dot, and for the R attribute,
  489.   read on.
  490.  
  491.   Under UNIX a file has ``permissions'' and an owner, who in turn
  492.   belongs to a ``group''. Look at this example:
  493.  
  494.  
  495.  
  496.        $ ls -l /bin/ls
  497.        -rwxr-xr-x  1  root  bin  27281 Aug 15 1995 /bin/ls*
  498.  
  499.  
  500.  
  501.  
  502.   The first field contains the permissions of the file /bin/ls, which
  503.   belongs to root, group bin. Leaving the remaining information aside,
  504.   remember that -rwxr-xr-x means, from left to right:
  505.  
  506.   - is the file type (- = ordinary file, d = directory, l = link, etc);
  507.   rwx are the permissions for the file owner (read, write, execute); r-x
  508.   are the permissions for the group of the file owner (read, execute);
  509.   (I won't cover the concept of group, you can survive without it as
  510.   long as you're a beginner ;-) r-x are the permissions for all other
  511.   users (read, execute).
  512.  
  513.   The directory /bin has permissions, too: see Section ``Directories
  514.   Permissions'' for further details. This is why you can't delete the
  515.   file /bin/ls unless you are root: you don't have the permission to do
  516.   so. To change a file's permissions, the command is:
  517.  
  518.  
  519.  
  520.        $ chmod <whoXperm> <file>
  521.  
  522.  
  523.  
  524.  
  525.   where who is u (user, that is owner), g (group), o (other), X is
  526.   either + or -, perm is r (read), w (write), or x (execute). Common
  527.   examples of chmod use are the following:
  528.  
  529.        $ chmod +x file
  530.  
  531.  
  532.  
  533.  
  534.   this sets the execute permission for the file.
  535.  
  536.  
  537.  
  538.        $ chmod go-rw file
  539.  
  540.  
  541.  
  542.  
  543.   this removes read and write permission for everyone but the owner.
  544.  
  545.  
  546.  
  547.        $ chmod ugo+rwx file
  548.  
  549.  
  550.  
  551.  
  552.   this gives everyone read, write, and execute permission.
  553.  
  554.  
  555.  
  556.        # chmod +s file
  557.  
  558.  
  559.  
  560.  
  561.   this makes a so-called ``setuid'' or ``suid'' file---a file that
  562.   everyone can execute with its owner's privileges. Typically, you'll
  563.   come across root suid files; these are often important system files,
  564.   like the X server.
  565.  
  566.   A shorter way to refer to permissions is with digits: rwxr-xr-x can be
  567.   expressed as 755 (every letter corresponds to a bit: --- is 0, --x is
  568.   1, -w- is 2, -wx is 3...). It looks difficult, but with a bit of
  569.   practice you'll understand the concept.
  570.  
  571.   root, being the superuser, can change everyone's file permissions.
  572.   RMP.
  573.  
  574.  
  575.  
  576.   3.4.  Files: Translating Commands
  577.  
  578.  
  579.   On the left, the DOS commands; on the right, their Linux counterpart.
  580.  
  581.  
  582.  
  583.        ATTRIB:         chmod
  584.        COPY:           cp
  585.        DEL:            rm
  586.        MOVE:           mv
  587.        REN:            mv
  588.        TYPE:           more, less, cat
  589.  
  590.  
  591.  
  592.  
  593.   Redirection and plumbing operators:  < > >> |
  594.  
  595.   Wildcards: * ?
  596.  
  597.   nul:        /dev/null
  598.  
  599.   prn, lpt1:  /dev/lp0 or /dev/lp1; lpr
  600.  
  601.  
  602.   3.4.1.  Examples
  603.  
  604.  
  605.  
  606.  
  607.  
  608.        DOS                                     Linux
  609.        ---------------------------------------------------------------------
  610.  
  611.        C:\GUIDO>ATTRIB +R FILE.TXT            $ chmod 400 file.txt
  612.        C:\GUIDO>COPY JOE.TXT JOE.DOC           $ cp joe.txt joe.doc
  613.        C:\GUIDO>COPY *.* TOTAL                $ cat * > total
  614.        C:\GUIDO>COPY FRACTALS.DOC PRN         $ lpr fractals.doc
  615.        C:\GUIDO>DEL TEMP                       $ rm temp
  616.        C:\GUIDO>DEL *.BAK                     $ rm *~
  617.        C:\GUIDO>MOVE PAPER.TXT TMP\          $ mv paper.txt tmp/
  618.        C:\GUIDO>REN PAPER.TXT PAPER.ASC       $ mv paper.txt paper.asc
  619.        C:\GUIDO>PRINT LETTER.TXT              $ lpr letter.txt
  620.        C:\GUIDO>TYPE LETTER.TXT               $ more letter.txt
  621.        C:\GUIDO>TYPE LETTER.TXT               $ less letter.txt
  622.        C:\GUIDO>TYPE LETTER.TXT > NUL         $ cat letter.txt > /dev/null
  623.                n/a                             $ more *.txt *.asc
  624.                n/a                             $ cat section*.txt | less
  625.  
  626.  
  627.  
  628.  
  629.   Notes:
  630.  
  631.  
  632.   ╖  * is smarter under Linux: * matches all files except the hidden
  633.      ones; .* matches all hidden files (but also the current directory
  634.      `.' and parent directory `..': beware!); *.* matches only those
  635.      that have a '.' in the middle or that end with a dot; p*r matches
  636.      both `peter' and `piper'; *c* matches both `picked' and `peck';
  637.  
  638.   ╖  when using more, press <SPACE> to read through the file, `q' to
  639.      exit. less is more intuitive and lets you use the arrow keys;
  640.  
  641.   ╖  there is no UNDELETE, so think twice before deleting anything;
  642.  
  643.   ╖  in addition to DOS' < > >>, Linux has 2> to redirect error messages
  644.      (stderr); moreover, 2>&1 redirects stderr to stdout, while 1>&2
  645.      redirects stdout to stderr;
  646.  
  647.   ╖  Linux has another wildcard: the []. Use: [abc]* matches files
  648.      starting with a, b, c; *[I-N1-3] matches files ending with I, J, K,
  649.      L, M, N, 1, 2, 3;
  650.  
  651.   ╖  lpr <file> prints a file in background. To check the status of the
  652.      print queue, use lpq; to remove a file from the print queue, use
  653.      lprm;
  654.  
  655.   ╖  there is no DOS-like RENAME; that is, mv *.xxx *.yyy won't work.
  656.      You could try this simple script; see Section ``Shell Scripts: .BAT
  657.      Files on Steroids'' for details.
  658.  
  659.  
  660.  
  661.      ___________________________________________________________________
  662.      #!/bin/sh
  663.      # ren: rename multiple files according to several rules
  664.  
  665.      if [ $# -lt 3 ] ; then
  666.        echo "usage: ren \"pattern\" \"replacement\" files..."
  667.        exit 1
  668.      fi
  669.  
  670.      OLD=$1 ; NEW=$2 ; shift ; shift
  671.  
  672.      for file in $*
  673.      do
  674.        new=`echo ${file} | sed s/${OLD}/${NEW}/g`
  675.        mv ${file} $new
  676.      done
  677.      ___________________________________________________________________
  678.  
  679.  
  680.  
  681.   Beware: it doesn't behave like DOS' REN, as it uses ``regular expres¡
  682.   sions'' that you still don't know. Shortly, if you simply want to
  683.   change file extensions, use it as in: ren "htm$" "html" *htm.  Don't
  684.   forget the $ sign.
  685.  
  686.   ╖  use cp -i and mv -i to be warned when a file is going to be
  687.      overwritten.
  688.  
  689.  
  690.  
  691.   3.5.  Running Programs: Multitasking and Sessions
  692.  
  693.  
  694.   To run a program, type its name as you would do under DOS. If the
  695.   directory (Section ``Using Directories'') where the program is stored
  696.   is included in the PATH (Section ``System Initialisation Files''), the
  697.   program will start. Exception: unlike DOS, under Linux a program
  698.   located in the current directory won't run unless the directory is
  699.   included in the PATH. Escamotage: being prog your program, type
  700.   ./prog.
  701.  
  702.   This is what the typical command line looks like:
  703.  
  704.  
  705.  
  706.        $ command [-s1 [-s2] ... [-sn]] [par1 [par2] ... [parn]] [< input] [> output]
  707.  
  708.  
  709.  
  710.  
  711.   where -s1, ..., -sn are the program switches, par1, ..., parn are the
  712.   program parameters. You can issue several commands on the command
  713.   line:
  714.  
  715.  
  716.  
  717.        $ command1 ; command2 ; ... ; commandn
  718.  
  719.  
  720.  
  721.  
  722.   That's all about running programs, but it's easy to go a step beyond.
  723.   One of the main reasons for using Linux is that it is a multitasking
  724.   os---it can run several programs (from now on, processes) at the same
  725.   time. You can launch processes in background and continue working
  726.   straight away. Moreover, Linux lets you have several sessions: it's
  727.   like having many computers to work on at once!
  728.  
  729.  
  730.   ╖  To switch to session 1..6 on the virtual consoles, press <ALT-F1>
  731.      ... <ALT-F6>
  732.  
  733.   ╖  To start a new session in the same v.c. without leaving the current
  734.      one, type su - <loginname>. Example: su - root. This is useful, for
  735.      instance, when you need to perform a task that only root can do.
  736.  
  737.   ╖  To end a session, type exit. If there are stopped jobs (see later),
  738.      you'll be warned.
  739.  
  740.   ╖  To launch a process in background, add an ampersand '&' at the end
  741.      of the command line:
  742.  
  743.  
  744.  
  745.        $ progname [-switches] [parameters] [< input] [> output] &
  746.        [1] 123
  747.  
  748.  
  749.  
  750.  
  751.  
  752.   the shell identifies the process with a job number (e.g. [1]; see
  753.   below), and with a PID (Process Identification Number; 123 in our
  754.   example).
  755.  
  756.   ╖  To see how many processes there are, type ps -ax. This will output
  757.      a list of currently running processes.
  758.  
  759.   ╖  To kill a process, type kill <PID>. You may need to kill a process
  760.      when you don't know how to quit it the right way.... Unless you're
  761.      root, you can't kill other people's processes. Sometimes, a process
  762.      will only be killed by kill -SIGKILL <PID>.
  763.  
  764.      In addition, the shell allows you to stop or temporarily suspend a
  765.      process, send a process to background, and bring a process from
  766.      background to foreground. In this context, processes are called
  767.      ``jobs''.
  768.  
  769.   ╖  To see how many jobs there are, type jobs. Here the jobs are
  770.      identified by their job number, not by their PID.
  771.  
  772.   ╖  To stop a process running in foreground, press <CTRL-C> (it won't
  773.      always work).
  774.  
  775.   ╖  To suspend a process running in foreground, press <CTRL-Z> (ditto).
  776.  
  777.   ╖  To send a suspended process into background, type bg <job> (it
  778.      becomes a job).
  779.  
  780.   ╖  To bring a job to foreground, type fg <job>. To foreground the last
  781.      backgrounded (is my English weird?) job, simply type fg.
  782.  
  783.   ╖  To kill a job, type kill <%job> where <job> may be 1, 2, 3,...
  784.  
  785.   Using these commands you can format a disk, zip a bunch of files,
  786.   compile a program, and unzip an archive all at the same time, and
  787.   still have the prompt at your disposal. Try this with DOS! And try
  788.   with Windows, just to see the difference in performance (if it doesn't
  789.   crash, of course).
  790.  
  791.  
  792.  
  793.   3.6.  Running Programs on Remote Computers
  794.  
  795.  
  796.   To run a program on a remote machine whose IP address is
  797.   remote.machine.edu, you do:
  798.  
  799.  
  800.  
  801.        $ telnet remote.machine.edu
  802.  
  803.  
  804.  
  805.  
  806.   After logging in, start your favourite program. Needless to say, you
  807.   must have a shell account on the remote machine.
  808.  
  809.   If you have X11, you can even run an X application on a remote
  810.   computer, displaying it on your X screen. Let remote.machine.edu be
  811.   the remote X computer and let local.linux.box be your Linux machine.
  812.   To run from local.linux.box an X program that resides on
  813.   remote.machine.edu, do the following:
  814.  
  815.  
  816.   ╖  fire up X11, start an xterm or equivalent terminal emulator, then
  817.      type:
  818.  
  819.  
  820.  
  821.        $ xhost +remote.machine.edu
  822.        $ telnet remote.machine.edu
  823.  
  824.  
  825.  
  826.  
  827.  
  828.   ╖  after logging in, type:
  829.  
  830.  
  831.  
  832.        remote:$ DISPLAY=local.linux.box:0.0
  833.        remote:$ progname &
  834.  
  835.  
  836.  
  837.  
  838.  
  839.   (instead of DISPLAY..., you may have to write: setenv DISPLAY
  840.   local.linux.box:0.0. It depends on the remote shell.)
  841.  
  842.   Et voila! Now progname will start on remote.machine.edu and will be
  843.   displayed on your machine. Don't try this over the modem though, for
  844.   it's too slow to be usable.
  845.  
  846.  
  847.  
  848.   4.  Using Directories
  849.  
  850.  
  851.  
  852.   4.1.  Directories: Preliminary Notions
  853.  
  854.  
  855.   We have seen the differences between files under DOS and Linux. As for
  856.   directories, under DOS the root directory is \, under Linux / is.
  857.   Similarly, nested directories are separated by \ under DOS, by / under
  858.   Linux. Example of file paths:
  859.        DOS:    C:\PAPERS\GEOLOGY\MID_EOC.TEX
  860.        Linux:  /home/guido/papers/geology/middle_eocene.tex
  861.  
  862.  
  863.  
  864.  
  865.   As usual, .. is the parent directory and . is the current directory.
  866.   Remember that the system won't let you cd, rd, or md everywhere you
  867.   want. Each user starts from his or her own directory called 'home',
  868.   given by the system administrator; for instance, on my PC my home dir
  869.   is /home/guido.
  870.  
  871.  
  872.  
  873.   4.2.  Directories Permissions
  874.  
  875.  
  876.   Directories, too, have permissions. What we have seen in Section
  877.   ``Permissions and Ownership'' applies to directories as well (user,
  878.   group, and other). For a directory, rx means you can cd to that
  879.   directory, and w means that you can delete a file in the directory
  880.   (according to the file's permissions, of course), or the directory
  881.   itself.
  882.  
  883.   For example, to prevent other users from snooping in /home/guido/text:
  884.  
  885.  
  886.  
  887.        $ chmod o-rwx /home/guido/text
  888.  
  889.  
  890.  
  891.  
  892.  
  893.  
  894.   4.3.  Directories: Translating Commands
  895.  
  896.  
  897.  
  898.  
  899.        DIR:            ls, find, du
  900.        CD:             cd, pwd
  901.        MD:             mkdir
  902.        RD:             rmdir
  903.        DELTREE:        rm -R
  904.        MOVE:           mv
  905.  
  906.  
  907.  
  908.  
  909.  
  910.   4.3.1.  Examples
  911.  
  912.  
  913.  
  914.  
  915.  
  916.  
  917.  
  918.  
  919.  
  920.  
  921.  
  922.  
  923.  
  924.  
  925.   DOS                                     Linux
  926.   ---------------------------------------------------------------------
  927.  
  928.   C:\GUIDO>DIR                            $ ls
  929.   C:\GUIDO>DIR FILE.TXT                   $ ls file.txt
  930.   C:\GUIDO>DIR *.H *.C                    $ ls *.h *.c
  931.   C:\GUIDO>DIR/P                          $ ls | more
  932.   C:\GUIDO>DIR/A                          $ ls -l
  933.   C:\GUIDO>DIR *.TMP /S                   $ find / -name "*.tmp"
  934.   C:\GUIDO>CD                             $ pwd
  935.           n/a - see note                  $ cd
  936.           ditto                           $ cd ~
  937.           ditto                           $ cd ~/temp
  938.   C:\GUIDO>CD \OTHER                      $ cd /other
  939.   C:\GUIDO>CD ..\TEMP\TRASH               $ cd ../temp/trash
  940.   C:\GUIDO>MD NEWPROGS                    $ mkdir newprogs
  941.   C:\GUIDO>MOVE PROG ..                   $ mv prog ..
  942.   C:\GUIDO>MD \PROGS\TURBO                $ mkdir /progs/turbo
  943.   C:\GUIDO>DELTREE TEMP\TRASH             $ rm -R temp/trash
  944.   C:\GUIDO>RD NEWPROGS                    $ rmdir newprogs
  945.   C:\GUIDO>RD \PROGS\TURBO                $ rmdir /progs/turbo
  946.  
  947.  
  948.  
  949.  
  950.   Notes:
  951.  
  952.  
  953.   1. when using rmdir, the directory to remove must be empty. To delete
  954.      a directory and all of its contents, use rm -R (at your own risk).
  955.  
  956.   2. the character '~' is a shortcut for the name of your home
  957.      directory. The commands cd or cd ~ will take you to your home
  958.      directory from wherever you are; the command cd ~/tmp will take you
  959.      to /home/your_home/tmp.
  960.  
  961.   3. cd - ``undoes'' the last cd.
  962.  
  963.  
  964.  
  965.   5.  Floppies, Hard Disks, and the Like
  966.  
  967.  
  968.   There are two ways to manage devices under Linux: the DOS way and the
  969.   UNIX way. Take your pick.
  970.  
  971.  
  972.   5.1.  Managing Devices the DOS Way
  973.  
  974.  
  975.   Most Linux distributions include the Mtools suite, a set of commands
  976.   that are perfectly equivalent to their DOS counterpart, but start with
  977.   an `m': i.e., mformat, mdir, mdel, mmd, and so on. They can even
  978.   preserve long file names, but not file permissions. If you configure
  979.   Mtools editing a file called /etc/mtools.conf (a sample is provided),
  980.   you can also access the DOS/Win partition, the CD-ROM, and the Zip
  981.   drive.
  982.  
  983.   To format a fresh disk though, the mformat command won't do. As root,
  984.   you'll have to issue this command beforehand:
  985.  
  986.  
  987.  
  988.        # fdformat /dev/fd0H1440
  989.  
  990.  
  991.   Note: you can't access files on the floppy with a command like, say,
  992.   less a:file.txt! This is the disadvantage of the DOS way of mounting
  993.   disks.
  994.  
  995.  
  996.   5.2.  Managing Devices the UNIX Way
  997.  
  998.  
  999.   UNIX has a different way to handle devices than DOS/Win. There are no
  1000.   separate volumes like A: or C:; a disk, be it a floppy or whatever,
  1001.   becomes part of the local file system through an operation called
  1002.   ``mounting''. When you're done using the disk, before extracting it
  1003.   you must ``unmount'' it.
  1004.  
  1005.   Physically formatting a disk is one thing, making a file system on it
  1006.   is another. The DOS command FORMAT A: does both things, but under
  1007.   Linux there are separate commands. To format a floppy, see above; to
  1008.   create a file system:
  1009.  
  1010.  
  1011.  
  1012.        # mkfs -t ext2 -c /dev/fd0H1440
  1013.  
  1014.  
  1015.  
  1016.  
  1017.   You can use minix, vfat, dos or other formats instead of ext2. Once
  1018.   the disk is prepared, mount it with the command
  1019.  
  1020.  
  1021.  
  1022.        # mount -t ext2 /dev/fd0 /mnt
  1023.  
  1024.  
  1025.  
  1026.  
  1027.   specifying the right file system if you don't use ext2. Now you can
  1028.   address the files in the floppy. All you used to do with A: or B: is
  1029.   now done using /mnt instead. Examples:
  1030.  
  1031.  
  1032.  
  1033.        DOS                                     Linux
  1034.        ---------------------------------------------------------------------
  1035.  
  1036.        C:\GUIDO>DIR A:                         $ ls /mnt
  1037.        C:\GUIDO>COPY A:*.*                     $ cp /mnt/* .
  1038.        C:\GUIDO>COPY *.ZIP A:                  $ cp *.zip /mnt
  1039.        C:\GUIDO>EDIT A:FILE.TXT                $ jstar /mnt/file.txt
  1040.        C:\GUIDO>A:                             $ cd /mnt
  1041.        A:>_                                    /mnt/$ _
  1042.  
  1043.  
  1044.  
  1045.  
  1046.   When you've finished, before extracting the disk you must unmount it
  1047.   with the command
  1048.  
  1049.  
  1050.  
  1051.        # umount /mnt
  1052.  
  1053.  
  1054.  
  1055.  
  1056.  
  1057.   Obviously, you have to fdformat and mkfs only unformatted disks, not
  1058.   previously used ones. If you want to use the drive B:, refer to
  1059.   fd1H1440 and fd1 instead of fd0H1440 and fd0 in the examples above.
  1060.  
  1061.   Needless to say, what applies to floppies also applies to other
  1062.   devices; for instance, you may want to mount another hard disk or a
  1063.   CD-ROM drive. Here's how to mount the CD-ROM:
  1064.  
  1065.  
  1066.  
  1067.        # mount -t iso9660 /dev/cdrom /mnt
  1068.  
  1069.  
  1070.  
  1071.  
  1072.   This was the ``official'' way to mount your disks, but there's a trick
  1073.   in store. Since it's a bit of a nuisance having to be root to mount a
  1074.   floppy or a CD-ROM, every user can be allowed to mount them this way:
  1075.  
  1076.  
  1077.   ╖  as root, do the following:
  1078.  
  1079.  
  1080.  
  1081.        # mkdir /mnt/a: ; mkdir /mnt/a ; mkdir /mnt/cdrom
  1082.        # chmod 777 /mnt/a* /mnt/cd*
  1083.        # # make sure that the CD-ROM device is right
  1084.        # chmod 666 /dev/hdb ; chmod 666 /dev/fd*
  1085.  
  1086.  
  1087.  
  1088.  
  1089.  
  1090.   ╖  add in /etc/fstab the following lines:
  1091.  
  1092.  
  1093.  
  1094.        /dev/cdrom      /mnt/cdrom  iso9660 ro,user,noauto          0       0
  1095.        /dev/fd0        /mnt/a:     msdos   user,noauto             0       0
  1096.        /dev/fd0        /mnt/a      ext2    user,noauto             0       0
  1097.  
  1098.  
  1099.  
  1100.  
  1101.  
  1102.   Now, to mount a DOS floppy, an ext2 floppy, and a CD-ROM:
  1103.  
  1104.  
  1105.  
  1106.        $ mount /mnt/a:
  1107.        $ mount /mnt/a
  1108.        $ mount /mnt/cdrom
  1109.  
  1110.  
  1111.  
  1112.  
  1113.   /mnt/a, /mnt/a:, and /mnt/cdrom can now be accessed by every user.
  1114.   Remember that allowing everyone to mount disks this way is a gaping
  1115.   security hole, if you care.
  1116.  
  1117.   Two useful commands are df, which gives information on the mounted
  1118.   file systems, and du dirname which reports the disk space consumed by
  1119.   the directory.
  1120.  
  1121.  
  1122.  
  1123.   5.3.  Backing Up
  1124.  
  1125.  
  1126.   There are several packages to help you, but the very least you can do
  1127.   for a multi-volume backup is (as root):
  1128.  
  1129.  
  1130.  
  1131.        # tar -M -cvf /dev/fd0H1440 dir_to_backup/
  1132.  
  1133.  
  1134.  
  1135.  
  1136.   Make sure to have a formatted floppy in the drive, and several more
  1137.   ready.  To restore your stuff, insert the first floppy in the drive
  1138.   and do:
  1139.  
  1140.  
  1141.  
  1142.        # tar -M -xpvf /dev/fd0H1440
  1143.  
  1144.  
  1145.  
  1146.  
  1147.  
  1148.  
  1149.   6.  What About Windows?
  1150.  
  1151.  
  1152.   The ``equivalent'' of Windows is the graphic system X Window System,
  1153.   or X11 for short. Unlike Windows or the Mac, X11 wasn't designed for
  1154.   ease of use or to look good, but just to provide graphic facilities to
  1155.   UNIX workstations.  These are the main differences:
  1156.  
  1157.  
  1158.   ╖  while Windows looks and feels the same all over the world, X11 does
  1159.      not: it's much more configurable. X11's overall look is given by a
  1160.      key component called ``window manager'', of which you have a wide
  1161.      choice: fvwm, basic but nice and memory efficient, fvwm2-95,
  1162.      Afterstep, and many more. The w.m. is usually invoked by a file
  1163.      called .xinitrc;
  1164.  
  1165.   ╖  your w.m. can be configured so as a window acts as in, er, Windows:
  1166.      you click on it and it comes to foreground. Another possibility is
  1167.      that it comes to foreground when the mouse moves over it
  1168.      (``focus''). Also, the placement of windows on the screen can be
  1169.      automatic or interactive: if a strange frame appears instead of
  1170.      your program, left click where you want it to appear;
  1171.  
  1172.   ╖  most actions can be tailored editing one or more configuration
  1173.      files. Read the docs of your window manager; the configuration file
  1174.      can be .fvwmrc, .fvwm2rc95, .steprc, etc. A sample configuration
  1175.      file is typically found in /etc/X11/window-manager-
  1176.      name/system.window-manager-name;
  1177.  
  1178.   ╖  X11 applications are written using special libraries (``widget
  1179.      sets''); as several are available, applications look different. The
  1180.      most basic ones are those that use the Athena widgets (2--D look;
  1181.      xdvi, xman, xcalc); others use Motif (netscape), others still use
  1182.      Tcl/Tk, XForms, Qt, Gtk, and what have you. Some---not all---of
  1183.      these libraries provide roughly the same look and feel as Windows;
  1184.  
  1185.   ╖  well, not quite. The feel, unfortunately, can be incoherent. For
  1186.      instance, if you select a line of text using the mouse and press
  1187.      <BACKSPACE>, you'd expect the line to disappear, right? This
  1188.      doesn't work with Athena--based apps, but it does with Motif, Qt,
  1189.      Gtk, and Tcl/Tk ones;
  1190.  
  1191.   ╖  how the scrollbars and resizing work depends on the window manager
  1192.      and the widget set. Tip: if you find that the scrollbars don't
  1193.      behave as you would expect, try using the central button or the two
  1194.      buttons together to move them;
  1195.  
  1196.   ╖  applications don't have an icon by default, but they can have many.
  1197.      Most window managers feature a menu you recall by clicking on the
  1198.      desktop (``root window''); needless to say, the menu can be
  1199.      tailored. To change the root window appearance, use xsetroot or
  1200.      xloadimage;
  1201.  
  1202.   ╖  the clipboard can only contain text, and behaves strange. Once
  1203.      you've selected text, it's already copied to the clipboard: move
  1204.      elsewhere and press the central button to paste it. There's an
  1205.      application, xclipboard, that provides for multiple clipboard
  1206.      buffers;
  1207.  
  1208.   ╖  drag and drop is an option, and is only available if you use X11
  1209.      applications that support it.
  1210.  
  1211.   To save memory, one should use applications that use the same
  1212.   libraries, but this is difficult to do in practice.
  1213.  
  1214.   The K Desktop Environment project aims at making X11 look and behave
  1215.   as coherently as Windows; it's currently in early beta stage but,
  1216.   believe me, it's awesome. Point your browser to  <http://www.kde.org>.
  1217.  
  1218.  
  1219.  
  1220.   7.  Tailoring the System
  1221.  
  1222.  
  1223.  
  1224.   7.1.  System Initialisation Files
  1225.  
  1226.  
  1227.   Two important files under DOS are AUTOEXEC.BAT and CONFIG.SYS, which
  1228.   are used at boot time to initialise the system, set some environment
  1229.   variables like PATH and FILES, and possibly launch a program or batch
  1230.   file.  Under Linux there are lots of initialisation files, some of
  1231.   which you had better not tamper with until you know exactly what you
  1232.   are doing. I'll tell you what the most important are, anyway:
  1233.  
  1234.  
  1235.  
  1236.        FILES                                   NOTES
  1237.  
  1238.        /etc/inittab                            don't touch for now!
  1239.        /etc/rc.d/*                             ditto
  1240.  
  1241.  
  1242.  
  1243.  
  1244.   If all you need is setting the $PATH and other environment variables,
  1245.   or you want to change the login messages or automatically launch a
  1246.   program after the login, have a look at the following files:
  1247.  
  1248.  
  1249.  
  1250.  
  1251.  
  1252.  
  1253.  
  1254.  
  1255.   FILES                                   NOTES
  1256.  
  1257.   /etc/issue                              sets pre-login message
  1258.   /etc/motd                               sets post-login message
  1259.   /etc/profile                            sets $PATH and other variables, etc.
  1260.   /etc/bashrc                             sets aliases and functions, etc.
  1261.   /home/your_home/.bashrc                 sets your aliases + functions
  1262.   /home/your_home/.bash_profile   or
  1263.   /home/your_home/.profile                sets environment + starts your progs
  1264.  
  1265.  
  1266.  
  1267.  
  1268.   If the latter file exists (note that it is a hidden file), it will be
  1269.   read after the login and the commands in it will be executed.
  1270.  
  1271.   Example---look at this .bash_profile:
  1272.  
  1273.  
  1274.   ______________________________________________________________________
  1275.   # I am a comment
  1276.   echo Environment:
  1277.   printenv | less   # equivalent of command SET under DOS
  1278.   alias d='ls -l'   # easy to understand what an alias is
  1279.   alias up='cd ..'
  1280.   echo "I remind you that the path is "$PATH
  1281.   echo "Today is `date`"  # use the output of command 'date'
  1282.   echo "Have a good day, "$LOGNAME
  1283.   # The following is a "shell function"
  1284.   ctgz() # List the contents of a .tar.gz archive.
  1285.   {
  1286.     for file in $*
  1287.     do
  1288.       gzip -dc ${file} | tar tf -
  1289.     done
  1290.   }
  1291.   # end of .profile
  1292.   ______________________________________________________________________
  1293.  
  1294.  
  1295.  
  1296.   $PATH and $LOGNAME, you guessed right, are environment variables.
  1297.   There are many others to play with; for instance, RMP for apps like
  1298.   less or bash.
  1299.  
  1300.  
  1301.  
  1302.   7.2.  Program Initialisation Files
  1303.  
  1304.  
  1305.   Under Linux, virtually everything can be tailored to your needs. Most
  1306.   programs have one or more initialisation files you can fiddle with,
  1307.   often as a .prognamerc in your home dir. The first ones you'll want to
  1308.   modify are:
  1309.  
  1310.  
  1311.   ╖   .inputrc: used by bash to define key bindings;
  1312.  
  1313.   ╖   .xinitrc: used by startx to initialise X Window System;
  1314.  
  1315.   ╖   .fvwmrc: used by the window manager fvwm.
  1316.  
  1317.   ╖   .joerc: used by the editor joe;
  1318.  
  1319.   ╖   .jedrc: used by the editor jed;
  1320.  
  1321.   ╖   .pinerc: used by the mail reader pine;
  1322.  
  1323.   ╖   .Xdefault: used by many X programs.
  1324.  
  1325.   For all of these and the others you'll come across sooner or later,
  1326.   RMP. As a final note, let me suggest that you check out the
  1327.   Configuration HOWTO on
  1328.     <http://sunsite.unc.edu/mdw/HOWTO/Config-HOWTO.html> .
  1329.  
  1330.  
  1331.  
  1332.   8.  A Bit of Programming
  1333.  
  1334.  
  1335.  
  1336.  
  1337.   8.1.  Shell Scripts: .BAT Files on Steroids
  1338.  
  1339.  
  1340.   If you used .BAT files to create shortcuts of long command lines (I
  1341.   did a lot), this goal can be attained by inserting appropriate alias
  1342.   lines (see example above) in profile or .profile. But if your .BATs
  1343.   were more complicated, then you'll love the scripting language made
  1344.   available by the shell: it's as powerful as QBasic, if not more. It
  1345.   has variables, structures like while, for, case, if... then... else,
  1346.   and lots of other features: it can be a good alternative to a ``real''
  1347.   programming language.
  1348.  
  1349.   To write a script---the equivalent of a .BAT file under DOS---all you
  1350.   have to do is write a standard ASCII file containing the instructions,
  1351.   save it, then make it executable with the command chmod +x
  1352.   <scriptfile>. To execute it, type its name.
  1353.  
  1354.   A word of warning. The system editor is called vi, and in my
  1355.   experience most new users find it very difficult to use. I'm not going
  1356.   to explain how to use it, because I don't like it and don't use it, so
  1357.   there. Suffice it here to say that:
  1358.  
  1359.  
  1360.   ╖  to insert some text, type `i' then your text;
  1361.  
  1362.   ╖  to delete characters, type <ESC> then `x';
  1363.  
  1364.   ╖  to quit vi whithout saving, type <ESC> then :q!
  1365.  
  1366.   ╖  to save and quit, type <ESC> then :wq.
  1367.  
  1368.   A good beginner editor is joe: invoking it by typing jstar you'll get
  1369.   the same key bindings as the DOS editor. jed in WordStar or IDE mode
  1370.   is even better. Please consult Section ``Where to Find Applications''
  1371.   to see where to get these editors.
  1372.  
  1373.   Writing scripts under bash is such a vast subject it would require a
  1374.   book by itself, and I will not delve into the topic any further. I'll
  1375.   just give you an example of shell script, from which you can extract
  1376.   some basic rules:
  1377.  
  1378.  
  1379.  
  1380.  
  1381.  
  1382.  
  1383.  
  1384.  
  1385.  
  1386.  
  1387.   ______________________________________________________________________
  1388.   #!/bin/sh
  1389.   # sample.sh
  1390.   # I am a comment
  1391.   # don't change the first line, it must be there
  1392.   echo "This system is: `uname -a`" # use the output of the command
  1393.   echo "My name is $0" # built-in variables
  1394.   echo "You gave me the following $# parameters: "$*
  1395.   echo "The first parameter is: "$1
  1396.   echo -n "What's your name? " ; read your_name
  1397.   echo notice the difference: "hi $your_name" # quoting with "
  1398.   echo notice the difference: 'hi $your_name' # quoting with '
  1399.   DIRS=0 ; FILES=0
  1400.   for file in `ls .` ; do
  1401.     if [ -d ${file} ] ; then # if file is a directory
  1402.       DIRS=`expr $DIRS + 1`  # DIRS = DIRS + 1
  1403.     elif [ -f ${file} ] ; then
  1404.       FILES=`expr $FILES + 1`
  1405.     fi
  1406.     case ${file} in
  1407.       *.gif|*jpg) echo "${file}: graphic file" ;;
  1408.       *.txt|*.tex) echo "${file}: text file" ;;
  1409.       *.c|*.f|*.for) echo "${file}: source file" ;;
  1410.       *) echo "${file}: generic file" ;;
  1411.     esac
  1412.   done
  1413.   echo "there are ${DIRS} directories and ${FILES} files"
  1414.   ls | grep "ZxY--!!!WKW"
  1415.   if [ $? != 0 ] ; then # exit code of last command
  1416.     echo "ZxY--!!!WKW not found"
  1417.   fi
  1418.   echo "enough... type 'man bash' if you want more info."
  1419.   ______________________________________________________________________
  1420.  
  1421.  
  1422.  
  1423.  
  1424.  
  1425.   8.2.  C for Yourself
  1426.  
  1427.  
  1428.   Under UNIX, the system language is C, love it or hate it. Scores of
  1429.   other languages (Java, FORTRAN, Pascal, Lisp, Basic, Perl, awk...) are
  1430.   also available.
  1431.  
  1432.   Taken for granted that you know C, here are a couple of guidelines for
  1433.   those of you who have been spoilt by Turbo C++ or one of its DOS kin.
  1434.   Linux's C compiler is called gcc and lacks all the bells and whistles
  1435.   that usually accompany its DOS counterparts: no IDE, on-line help,
  1436.   integrated debugger, etc. It's just a rough command-line compiler,
  1437.   very powerful and efficient. To compile your standard hello.c you'll
  1438.   do:
  1439.  
  1440.  
  1441.  
  1442.        $ gcc hello.c
  1443.  
  1444.  
  1445.  
  1446.  
  1447.   which will create an executable file called a.out. To give the
  1448.   executable a different name, do
  1449.  
  1450.  
  1451.  
  1452.  
  1453.   $ gcc -o hola hello.c
  1454.  
  1455.  
  1456.  
  1457.  
  1458.   To link a library against a program, add the switch -l<libname>. For
  1459.   example, to link in the math library:
  1460.  
  1461.  
  1462.  
  1463.        $ gcc -o mathprog mathprog.c -lm
  1464.  
  1465.  
  1466.  
  1467.  
  1468.   (The -l<libname> switch forces gcc to link the library
  1469.   /usr/lib/lib<libname>.a; so -lm links /usr/lib/libm.a).
  1470.  
  1471.   So far, so good. But when your prog is made of several source files,
  1472.   you'll need to use the utility make. Let's suppose you have written an
  1473.   expression parser: its source file is called parser.c and #includes
  1474.   two header files, parser.h and xy.h. Then you want to use the routines
  1475.   in parser.c in a program, say, calc.c, which in turn #includes
  1476.   parser.h. What a mess! What do you have to do to compile calc.c?
  1477.  
  1478.   You'll have to write a so-called makefile, which teaches the compiler
  1479.   the dependencies between sources and objects files. In our example:
  1480.  
  1481.  
  1482.   ______________________________________________________________________
  1483.   # This is makefile, used to compile calc.c
  1484.   # Press the <TAB> key where indicated!
  1485.  
  1486.   calc: calc.o parser.o
  1487.   <TAB>gcc -o calc calc.o parser.o -lm
  1488.   # calc depends on two object files: calc.o and parser.o
  1489.  
  1490.   calc.o: calc.c parser.h
  1491.   <TAB>gcc -c calc.c
  1492.   # calc.o depends on two source files
  1493.  
  1494.   parser.o:  parser.c parser.h xy.h
  1495.   <TAB>gcc -c parser.c
  1496.   # parser.o depends on three source files
  1497.  
  1498.   # end of makefile.
  1499.   ______________________________________________________________________
  1500.  
  1501.  
  1502.  
  1503.   Save this file as Makefile and type make to compile your program;
  1504.   alternatively, save it as calc.mak and type make -f calc.mak, and of
  1505.   course RMP. You can invoke some help about the C functions, that are
  1506.   covered by man pages, section 3; for example,
  1507.  
  1508.  
  1509.  
  1510.        $ man 3 printf
  1511.  
  1512.  
  1513.  
  1514.  
  1515.   To debug your programs, use gdb. info gdb to learn how to use it.
  1516.  
  1517.   There are lots of libraries available; among the first you'll want to
  1518.   use are ncurses, to handle textmode effects, and svgalib, to do
  1519.   graphics. If you feel brave enough to tackle X11 programming, there
  1520.   are libraries like the abovementioned XForms, Qt, Gtk and many others,
  1521.   which make writing X11 programs a breeze. Have a look at
  1522.   <http://www.xnet.com/~blatura/linapp6.html> .
  1523.  
  1524.   Many editors can act as an IDE; emacs and jed, for instance, also
  1525.   feature syntax highlighting, automatic indent and so on.
  1526.   Alternatively, get the package rhide from
  1527.   <ftp://sunsite.unc.edu:/pub/Linux/devel/debuggers/>.  It's a Borland
  1528.   IDE clone, and chances are that you'll like it.
  1529.  
  1530.  
  1531.  
  1532.   9.  The Remaining 1%
  1533.  
  1534.  
  1535.   More than 1%, actually...
  1536.  
  1537.  
  1538.  
  1539.   9.1.  Using tar & gzip
  1540.  
  1541.  
  1542.   Under UNIX there are some widely used applications to archive and
  1543.   compress files. tar is used to make archives---it's like PKZIP but it
  1544.   doesn't compress, it only archives. To make a new archive:
  1545.  
  1546.  
  1547.  
  1548.        $ tar -cvf <archive_name.tar> <file> [file...]
  1549.  
  1550.  
  1551.  
  1552.  
  1553.   To extract files from an archive:
  1554.  
  1555.  
  1556.  
  1557.        $ tar -xpvf <archive_name.tar> [file...]
  1558.  
  1559.  
  1560.  
  1561.  
  1562.   To list the contents of an archive:
  1563.  
  1564.  
  1565.  
  1566.        $ tar -tf <archive_name.tar> | less
  1567.  
  1568.  
  1569.  
  1570.  
  1571.   You can compress files using compress, which is obsolete and shouldn't
  1572.   be used any more, or gzip:
  1573.  
  1574.  
  1575.  
  1576.        $ compress <file>
  1577.        $ gzip <file>
  1578.  
  1579.  
  1580.  
  1581.  
  1582.   that creates a compressed file with extension .Z (compress) or .gz
  1583.   (gzip). These programs can compress only one file at a time. To
  1584.   decompress, use:
  1585.        $ compress -d <file.Z>
  1586.        $ gzip -d <file.gz>
  1587.  
  1588.  
  1589.  
  1590.  
  1591.   RMP.
  1592.  
  1593.   There are also the unarj, zip and unzip (PK??ZIP compatible)
  1594.   utilities. Files with extension .tar.gz or .tgz (archived with tar,
  1595.   then compressed with gzip) are as common in the UNIX world as .ZIP
  1596.   files are under DOS. Here's how to list the contents of a
  1597.    .tar.gz archive:
  1598.  
  1599.  
  1600.  
  1601.        $ tar -ztf <file.tar.gz> | less
  1602.  
  1603.  
  1604.  
  1605.  
  1606.  
  1607.  
  1608.   9.2.  Installing Applications
  1609.  
  1610.  
  1611.   First of all: installing packages is root's work. Most Linux
  1612.   applications are distributed as a .tar.gz archive, which typically
  1613.   will contain a directory called pkgname/ containing files and/or
  1614.   subdirectories.  A good rule is to install these packages from
  1615.   /usr/local with the command
  1616.  
  1617.  
  1618.  
  1619.        # tar -zxf <archive.tar.gz>
  1620.  
  1621.  
  1622.  
  1623.  
  1624.   reading then the README or INSTALL file. In many cases, the package is
  1625.   distributed in source, which you'll have to compile to create the
  1626.   binaries; often, typing make then make installwill suffice.
  1627.   Obviously, you'll need the gcc or g++ compiler.
  1628.  
  1629.   Other archives may have to be unpacked from /; this is the case with
  1630.   Slackware's .tgz archives. Other archives contain the files but not a
  1631.   subdirectory. Always list the contents of the archive before
  1632.   installing it.
  1633.  
  1634.   The Debian and Red Hat distributions have their own archive format;
  1635.   respectively, .deb and .rpm. The latter is gaining wide acceptance; to
  1636.   install an .rpm package, type
  1637.  
  1638.  
  1639.  
  1640.        # rpm -i package.rpm
  1641.  
  1642.  
  1643.  
  1644.  
  1645.  
  1646.  
  1647.   9.3.  Tips You Can't Do Without
  1648.  
  1649.  
  1650.  
  1651.   Command completion: pressing <TAB> when issuing a command will
  1652.   complete the command line for you. Example: you have to type gcc
  1653.   this_is_a_long_name.c; typing gcc thi<TAB> will suffice. (If you have
  1654.   other files that start with the same characters, supply enough
  1655.   characters to resolve any ambiguity.)
  1656.  
  1657.   Backscrolling: pressing <SHIFT + PAG UP> (the grey key) allows you to
  1658.   backscroll a few pages, depending on how much video memory you have.
  1659.  
  1660.   Resetting the screen: if you happen to more or cat a binary file, your
  1661.   screen may end up full of garbage. To fix it, blind type reset or this
  1662.   sequence of characters: echo CTRL-V ESC c RETURN.
  1663.  
  1664.   Pasting text: in console, see below; in X, click and drag to select
  1665.   the text in an xterm window, then click the middle button (or the two
  1666.   buttons together if you have a two-button mouse) to paste. There is
  1667.   also xclipboard (alas, only for text); don't get confused by its very
  1668.   slow response.
  1669.  
  1670.   Using the mouse: if you installed gpm, a mouse driver for the console,
  1671.   you can click and drag to select text, then right click to paste the
  1672.   selected text. It works across different VCs.
  1673.  
  1674.   Messages from the kernel: have a look at /var/adm/messages or
  1675.   /var/log/messages as root to see what the kernel has to tell you,
  1676.   including bootup messages. The command dmesg is also handy.
  1677.  
  1678.  
  1679.  
  1680.   9.4.  Where to Find Applications
  1681.  
  1682.  
  1683.   If you're wondering whether there are applications to replace your old
  1684.   DOS/Win ones, I suggest that you browse the main Linux software
  1685.   repositories:
  1686.     <ftp://sunsite.unc.edu/pub/Linux> ,
  1687.    <ftp://tsx-11.mit.edu/pub/linux> , and
  1688.    <ftp://ftp.funet.fi/pub/Linux> .  Another excellent place is the
  1689.   ``Linux Applications and Utilities Page'' at
  1690.     <http://www.xnet.com/~blatura/linapps.shtml> .
  1691.  
  1692.  
  1693.  
  1694.   9.5.  A Few Things You Couldn't Do
  1695.  
  1696.  
  1697.   Linux can do an awful lot of things that were cumbersome, difficult or
  1698.   impossible do to with DOS/Win. Here's a short list that may whet your
  1699.   appetite:
  1700.  
  1701.  
  1702.   ╖  at allows you to run programs at a specified time;
  1703.  
  1704.   ╖  awk is a simple yet powerful language to manipulate data files (and
  1705.      not only). For example, being data.dat your multi field data file,
  1706.  
  1707.  
  1708.  
  1709.        $ awk '$2 ~ "abc" {print $1, "\t", $4}' data.dat
  1710.  
  1711.  
  1712.  
  1713.  
  1714.  
  1715.   prints out fields 1 and 4 of every line in data.dat whose second field
  1716.   contains ``abc''.
  1717.   ╖  cron is useful to perform tasks periodically, at specified date and
  1718.      time. Type man 5 crontab.
  1719.  
  1720.   ╖  file <filename> tells you what filename is (ASCII text, executable,
  1721.      archive, etc.);
  1722.  
  1723.   ╖  find (see also Section ``Directories: Translating Commands'') is
  1724.      one of the most powerful and useful commands. It's used to find
  1725.      files that match several characteristics and perform actions on
  1726.      them. General use of find is:
  1727.  
  1728.  
  1729.  
  1730.        $ find <directory> <expression>
  1731.  
  1732.  
  1733.  
  1734.  
  1735.  
  1736.   where <expression> includes search criteria and actions. Examples:
  1737.  
  1738.  
  1739.  
  1740.        $ find . -type l -exec ls -l {} \;
  1741.  
  1742.  
  1743.  
  1744.  
  1745.  
  1746.   finds all the files that are symbolic links and shows what they point
  1747.   to.
  1748.  
  1749.  
  1750.  
  1751.        $ find / -name "*.old" -ok rm {} \;
  1752.  
  1753.  
  1754.  
  1755.  
  1756.  
  1757.   finds all the files matching the pattern and deletes them, asking for
  1758.   your permission first.
  1759.  
  1760.  
  1761.  
  1762.        $ find . -perm +111
  1763.  
  1764.  
  1765.  
  1766.  
  1767.  
  1768.   finds all the files whose permissions match 111 (executable).
  1769.  
  1770.  
  1771.  
  1772.        $ find . -user root
  1773.  
  1774.  
  1775.  
  1776.  
  1777.  
  1778.   finds all the files that belong to root. Lots of possibilities
  1779.   here---RMP.
  1780.  
  1781.   ╖  grep finds text patterns in files. For example,
  1782.  
  1783.        $ grep -l "geology" *.tex
  1784.  
  1785.  
  1786.  
  1787.  
  1788.  
  1789.   lists the files *.tex that contain the word ``geology''. The variant
  1790.   zgrep works on gzipped files. RMP;
  1791.  
  1792.   ╖  regular expressions are a complex but darn powerful way of
  1793.      performing search operations on text. For example, ^a[^a-
  1794.      m]X{4,}txt$ matches a line that starts with `a', followed by any
  1795.      character except those in the interval a-m, followed by 4 or more
  1796.      `X', and ends in `txt'. You use regular expressions with advanced
  1797.      editors, less, and many other applications. man grep for an
  1798.      introduction.
  1799.  
  1800.   ╖  script <script_file> dumps the screen contents on script_file until
  1801.      you issue the command exit. Useful for debugging;
  1802.  
  1803.   ╖  sudo allows users to perform some of root's tasks (e.g.  formatting
  1804.      and mounting disks; RMP);
  1805.  
  1806.   ╖  uname -a gives you info about your system;
  1807.  
  1808.   ╖  The following commands often come in handy: bc, cal, chsh, cmp,
  1809.      cut, fmt, head, hexdump, nl, passwd, printf, sort, split, strings,
  1810.      tac, tail, tee, touch, uniq, w, wall, wc, whereis, write, xargs,
  1811.      znew. RMP.
  1812.  
  1813.  
  1814.  
  1815.   9.6.  Common Extensions and Related Programs
  1816.  
  1817.  
  1818.   You may come across scores of file extensions. Excluding the more
  1819.   exotic ones (i.e. fonts, etc.), here's a list of who's what:
  1820.  
  1821.  
  1822.   ╖  1 ... 8: man pages. In the unlikely case you don't yet have it, get
  1823.      man.
  1824.  
  1825.   ╖  arj: archive made with arj.
  1826.  
  1827.   ╖  dvi: output file produced by TeX (see below). xdvi to visualise it;
  1828.      dvips to turn it into a PostScript .ps file.
  1829.  
  1830.   ╖  gz: archive made with gzip.
  1831.  
  1832.   ╖  info: info file (sort of alternative to man pages). Get info.
  1833.  
  1834.   ╖  lsm: Linux Software Map file. It's a plain ASCII file containing
  1835.      the description of a package.
  1836.  
  1837.   ╖  ps: PostScript file. To visualise or print it get gs and,
  1838.      optionally, ghostview or gv.
  1839.  
  1840.   ╖  rpm: Red Hat package. You can install it on any system using the
  1841.      package manager rpm.
  1842.  
  1843.   ╖  taz, tar.Z: archive made with tar and compressed with compress.
  1844.  
  1845.   ╖  tgz, tar.gz: archive made with tar and compressed with gzip.
  1846.  
  1847.   ╖  tex: text file to submit to TeX, a powerful typesetting system.
  1848.      Get the package tex, available in many distributions; but beware of
  1849.      NTeX, which has corrupted fonts and is included in some Slackware
  1850.      versions.
  1851.  
  1852.   ╖  texi: texinfo file, can produce both TeX and info files (cp.
  1853.      info). Get texinfo.
  1854.  
  1855.   ╖  xbm, xpm, xwd: graphic file. Get xpaint.
  1856.  
  1857.   ╖  Z: archive made with compress.
  1858.  
  1859.  
  1860.  
  1861.   9.7.  Converting Files
  1862.  
  1863.  
  1864.   If you need to exchange text files between DOS/Win and Linux, beware
  1865.   of the ``end of line'' problem. Under DOS, each line of text ends with
  1866.   CR/LF, while under Linux with LF. If you try to edit a DOS text file
  1867.   under Linux, each line will likely end with a strange--looking `M'
  1868.   character; a Linux text file under DOS will appear as a kilometric
  1869.   single line with no paragraphs. There are a couple of tools, dos2unix
  1870.   and unix2dos, to convert the files.
  1871.  
  1872.   If your files contain accented characters, make sure they are made
  1873.   under Windows (with Write or Notepad, say) and not under plain DOS;
  1874.   otherwise, all accented characters will be screwed up.
  1875.  
  1876.   To convert Word or WordPerfect files to plain text, the matter is a
  1877.   bit trickier but possible. You'll need one of the tools that can be
  1878.   found on the CTAN sites; one is   <ftp://ftp.tex.ac.uk> .  Get the
  1879.   package word2x from the directory /pub/tex/tools/', or try one the
  1880.   packages available in directory /pub/tex/support/. I've only tried
  1881.   word2x, and works quite well.
  1882.  
  1883.  
  1884.  
  1885.   10.  The End, for Now
  1886.  
  1887.  
  1888.   Congratulations! You have now grasped a little bit of UNIX and are
  1889.   ready to start working. Remember that your knowledge of the system is
  1890.   still limited, and that you are expected to do more practice with
  1891.   Linux to use it comfortably. But if all you had to do was get a bunch
  1892.   of applications and start working with them, what I included here is
  1893.   enough.
  1894.  
  1895.   I'm sure you'll enjoy using Linux and will keep learning more about
  1896.   it---everybody does. I bet, too, that you'll never go back to DOS/Win!
  1897.   I hope I made myself understood and did a good service to my 3 or 4
  1898.   readers.
  1899.  
  1900.  
  1901.  
  1902.   10.1.  Copyright
  1903.  
  1904.  
  1905.   Unless otherwise stated, Linux HOWTO documents are copyrighted by
  1906.   their respective authors. Linux HOWTO documents may be reproduced and
  1907.   distributed in whole or in part, in any medium physical or electronic,
  1908.   as long as this copyright notice is retained on all copies. Commercial
  1909.   redistribution is allowed and encouraged; however, the author would
  1910.   like to be notified of any such distributions.
  1911.  
  1912.   All translations, derivative works, or aggregate works incorporating
  1913.   any Linux HOWTO documents must be covered under this copyright notice.
  1914.   That is, you may not produce a derivative work from a HOWTO and impose
  1915.   additional restrictions on its distribution. Exceptions to these rules
  1916.   may be granted under certain conditions; please contact the Linux
  1917.   HOWTO coordinator at the address given below.
  1918.  
  1919.   In short, we wish to promote dissemination of this information through
  1920.   as many channels as possible. However, we do wish to retain copyright
  1921.   on the HOWTO documents, and would like to be notified of any plans to
  1922.   redistribute the HOWTOs.
  1923.  
  1924.   If you have questions, please contact Tim Bynum, the Linux HOWTO
  1925.   coordinator, at linux-howto@sunsite.unc.edu via email.
  1926.  
  1927.  
  1928.  
  1929.   10.2.  Disclaimer
  1930.  
  1931.  
  1932.   ``From DOS to Linux HOWTO'' was written by Guido Gonzato,
  1933.   guido@ibogfs.cineca.it.  Many thanks to Matt Welsh, the author of
  1934.   ``Linux Installation and Getting Started'', to Ian Jackson, the author
  1935.   of ``Linux frequently asked questions with answers'', to Giuseppe
  1936.   Zanetti, the author of ``Linux'', to all the folks who emailed me
  1937.   suggestions, and especially to Linus Torvalds and GNU who gave us
  1938.   Linux.
  1939.  
  1940.   This document is provided ``as is''. I put great effort into writing
  1941.   it as accurately as I could, but you use the information contained in
  1942.   it at your own risk. In no event shall I be liable for any damages
  1943.   resulting from the use of this work.
  1944.  
  1945.   Feedback is welcome. For any requests, suggestions, flames, etc., feel
  1946.   free to contact me.
  1947.  
  1948.   Enjoy Linux and life,
  1949.  
  1950.   Guido   =8-)
  1951.  
  1952.  
  1953.  
  1954.  
  1955.  
  1956.  
  1957.  
  1958.  
  1959.  
  1960.  
  1961.  
  1962.  
  1963.  
  1964.  
  1965.  
  1966.  
  1967.  
  1968.  
  1969.  
  1970.  
  1971.  
  1972.  
  1973.  
  1974.  
  1975.  
  1976.  
  1977.  
  1978.  
  1979.  
  1980.  
  1981.