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

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