4236 lines
76 KiB
HTML
4236 lines
76 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
|
<HTML
|
|
><HEAD
|
|
><TITLE
|
|
>From VMS to Linux HOWTO</TITLE
|
|
><META
|
|
NAME="GENERATOR"
|
|
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"></HEAD
|
|
><BODY
|
|
CLASS="ARTICLE"
|
|
BGCOLOR="#FFFFFF"
|
|
TEXT="#000000"
|
|
LINK="#0000FF"
|
|
VLINK="#840084"
|
|
ALINK="#0000FF"
|
|
><DIV
|
|
CLASS="ARTICLE"
|
|
><DIV
|
|
CLASS="TITLEPAGE"
|
|
><H1
|
|
CLASS="TITLE"
|
|
><A
|
|
NAME="AEN2"
|
|
></A
|
|
>From VMS to Linux HOWTO</H1
|
|
><H3
|
|
CLASS="AUTHOR"
|
|
><A
|
|
NAME="AEN4"
|
|
>By Guido Gonzato, �,
|
|
and Mike Miller, �</A
|
|
></H3
|
|
><P
|
|
CLASS="PUBDATE"
|
|
>v1.1.4, 22 September 2004<BR></P
|
|
><DIV
|
|
><DIV
|
|
CLASS="ABSTRACT"
|
|
><A
|
|
NAME="AEN9"
|
|
></A
|
|
><P
|
|
></P
|
|
><P
|
|
>This HOWTO is aimed at all those who have been using VMS and now need or
|
|
want to switch to Linux, the free UNIX clone. The transition is made
|
|
(hopefully) painless with a step--to--step comparison between commands and
|
|
available tools.</P
|
|
><P
|
|
></P
|
|
></DIV
|
|
></DIV
|
|
><HR></DIV
|
|
><DIV
|
|
CLASS="TOC"
|
|
><DL
|
|
><DT
|
|
><B
|
|
>Table of Contents</B
|
|
></DT
|
|
><DT
|
|
>1. <A
|
|
HREF="#INTRODUCTION"
|
|
>Introduction</A
|
|
></DT
|
|
><DD
|
|
><DL
|
|
><DT
|
|
>1.1. <A
|
|
HREF="#AEN13"
|
|
>Why Linux?</A
|
|
></DT
|
|
><DT
|
|
>1.2. <A
|
|
HREF="#AEN47"
|
|
>Comparing Commands and Files</A
|
|
></DT
|
|
></DL
|
|
></DD
|
|
><DT
|
|
>2. <A
|
|
HREF="#SHORT-INTRO"
|
|
>Short Intro</A
|
|
></DT
|
|
><DD
|
|
><DL
|
|
><DT
|
|
>2.1. <A
|
|
HREF="#AEN56"
|
|
>Files</A
|
|
></DT
|
|
><DT
|
|
>2.2. <A
|
|
HREF="#AEN79"
|
|
>Directories</A
|
|
></DT
|
|
><DT
|
|
>2.3. <A
|
|
HREF="#AEN112"
|
|
>Programs</A
|
|
></DT
|
|
><DT
|
|
>2.4. <A
|
|
HREF="#QUICK-TOUR"
|
|
>Quick Tour</A
|
|
></DT
|
|
></DL
|
|
></DD
|
|
><DT
|
|
>3. <A
|
|
HREF="#EDITING-FILES"
|
|
>Editing Files</A
|
|
></DT
|
|
><DT
|
|
>4. <A
|
|
HREF="#TEXING"
|
|
>TeXing</A
|
|
></DT
|
|
><DT
|
|
>5. <A
|
|
HREF="#PROGRAMMING"
|
|
>Programming</A
|
|
></DT
|
|
><DD
|
|
><DL
|
|
><DT
|
|
>5.1. <A
|
|
HREF="#AEN284"
|
|
>Fortran</A
|
|
></DT
|
|
><DT
|
|
>5.2. <A
|
|
HREF="#AEN326"
|
|
>Using <TT
|
|
CLASS="LITERAL"
|
|
>make</TT
|
|
></A
|
|
></DT
|
|
><DT
|
|
>5.3. <A
|
|
HREF="#AEN345"
|
|
>Shell Scripts</A
|
|
></DT
|
|
><DT
|
|
>5.4. <A
|
|
HREF="#C"
|
|
>C</A
|
|
></DT
|
|
></DL
|
|
></DD
|
|
><DT
|
|
>6. <A
|
|
HREF="#GRAPHICS"
|
|
>Graphics</A
|
|
></DT
|
|
><DT
|
|
>7. <A
|
|
HREF="#MAIL-AND-INTERNET-TOOLS"
|
|
>Mail and Internet Tools</A
|
|
></DT
|
|
><DT
|
|
>8. <A
|
|
HREF="#ADVANCED-TOPICS"
|
|
>Advanced Topics</A
|
|
></DT
|
|
><DD
|
|
><DL
|
|
><DT
|
|
>8.1. <A
|
|
HREF="#PERMISSIONS"
|
|
>Permissions and Ownership</A
|
|
></DT
|
|
><DT
|
|
>8.2. <A
|
|
HREF="#MULTITASKING"
|
|
>Multitasking: Processes and Jobs</A
|
|
></DT
|
|
><DT
|
|
>8.3. <A
|
|
HREF="#AEN542"
|
|
>Files, Revisited</A
|
|
></DT
|
|
><DT
|
|
>8.4. <A
|
|
HREF="#PRINT-QUEUES"
|
|
>Print Queues</A
|
|
></DT
|
|
></DL
|
|
></DD
|
|
><DT
|
|
>9. <A
|
|
HREF="#CONFIGURING"
|
|
>Configuring</A
|
|
></DT
|
|
><DT
|
|
>10. <A
|
|
HREF="#USEFUL-PROGRAMS"
|
|
>Useful Programs</A
|
|
></DT
|
|
><DD
|
|
><DL
|
|
><DT
|
|
>10.1. <A
|
|
HREF="#AEN617"
|
|
>Browsing Files: <TT
|
|
CLASS="LITERAL"
|
|
>less</TT
|
|
></A
|
|
></DT
|
|
><DT
|
|
>10.2. <A
|
|
HREF="#NUMBERED-BACKUPS-UNDER-LINUX"
|
|
>Numbered Backups Under Linux</A
|
|
></DT
|
|
><DT
|
|
>10.3. <A
|
|
HREF="#AEN672"
|
|
>Archiving: tar & gzip</A
|
|
></DT
|
|
></DL
|
|
></DD
|
|
><DT
|
|
>11. <A
|
|
HREF="#EXAMPLES"
|
|
>Real Life Examples</A
|
|
></DT
|
|
><DT
|
|
>12. <A
|
|
HREF="#AEN811"
|
|
>Tips You Can't Do Without</A
|
|
></DT
|
|
><DT
|
|
>13. <A
|
|
HREF="#AEN838"
|
|
>Reading VMS tapes from Linux</A
|
|
></DT
|
|
><DD
|
|
><DL
|
|
><DT
|
|
>13.1. <A
|
|
HREF="#AEN841"
|
|
>Introduction</A
|
|
></DT
|
|
><DT
|
|
>13.2. <A
|
|
HREF="#AEN846"
|
|
>The Basics</A
|
|
></DT
|
|
><DT
|
|
>13.3. <A
|
|
HREF="#AEN858"
|
|
>Some details</A
|
|
></DT
|
|
><DT
|
|
>13.4. <A
|
|
HREF="#AEN866"
|
|
>Comment on Block Size</A
|
|
></DT
|
|
></DL
|
|
></DD
|
|
><DT
|
|
>14. <A
|
|
HREF="#AEN871"
|
|
>The End</A
|
|
></DT
|
|
><DD
|
|
><DL
|
|
><DT
|
|
>14.1. <A
|
|
HREF="#AEN873"
|
|
>Copyright</A
|
|
></DT
|
|
><DT
|
|
>14.2. <A
|
|
HREF="#AEN880"
|
|
>Disclaimer</A
|
|
></DT
|
|
></DL
|
|
></DD
|
|
></DL
|
|
></DIV
|
|
><DIV
|
|
CLASS="SECT1"
|
|
><H1
|
|
CLASS="SECT1"
|
|
><A
|
|
NAME="INTRODUCTION"
|
|
></A
|
|
>1. Introduction</H1
|
|
><DIV
|
|
CLASS="SECT2"
|
|
><H2
|
|
CLASS="SECT2"
|
|
><A
|
|
NAME="AEN13"
|
|
></A
|
|
>1.1. Why Linux?</H2
|
|
><P
|
|
>You've heard that UNIX is difficult and balk at the prospect of leaving VMS,
|
|
don't you? Don't worry. Linux, one of the finest UNIX clones, is not more
|
|
difficult to use than VMS; actually, I find it easier. Although VMS
|
|
aficionados may not agree, in many people's opinion Linux is much more
|
|
powerful and versatile.</P
|
|
><P
|
|
>Linux and VMS are both good operating systems and accomplish essentially the
|
|
same tasks, but Linux has a few features that make it a good alternative to
|
|
VMS. Moreover, Linux is available for PCs while VMS is not, and modern
|
|
Pentium-based Linux machines can outperform a VAX. The icing on the cake is
|
|
the excellent performance of modern video cards, which turn an X11-based
|
|
Linux box into a fast graphic workstation; nearly always, quicker than
|
|
dedicated machines.</P
|
|
><P
|
|
>I imagine you're a university researcher or a student, and that you use
|
|
VMS for the following everyday tasks:</P
|
|
><P
|
|
> <P
|
|
></P
|
|
><UL
|
|
><LI
|
|
><P
|
|
> writing papers with TeX/LaTeX;</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> programming in Fortran;</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> doing some graphics;</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> using Internet services;</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> et cetera. </P
|
|
></LI
|
|
></UL
|
|
> </P
|
|
><P
|
|
>In the following sections I'm going to explain to you how to do these
|
|
tasks under Linux, exploiting your experience with VMS. Prerequisites:</P
|
|
><P
|
|
> <P
|
|
></P
|
|
><UL
|
|
><LI
|
|
><P
|
|
> Linux and X Window System are properly installed; </P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> there's a system administrator to take care of the technical
|
|
details (please get help from them, not from me ;-) ; </P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> your shell---the equivalent of <TT
|
|
CLASS="LITERAL"
|
|
>DCL</TT
|
|
>---is <TT
|
|
CLASS="LITERAL"
|
|
>bash</TT
|
|
> (ask your
|
|
sysadm). </P
|
|
></LI
|
|
></UL
|
|
> </P
|
|
><P
|
|
>Please note that this HOWTO is not enough to acquaint you fully with
|
|
Linux: it only contains the bare essential to get you started. You
|
|
should learn more about Linux to make the most of it (advanced <TT
|
|
CLASS="LITERAL"
|
|
>bash</TT
|
|
>
|
|
features, programming, regular expressions...). From now on, RMP means
|
|
`please read the man pages for further details'. The man pages are the
|
|
equivalent of the command <TT
|
|
CLASS="LITERAL"
|
|
>HELP</TT
|
|
>.</P
|
|
><P
|
|
>The Linux Documentation Project documents, available on <A
|
|
HREF="ftp://sunsite.unc.edu:/pub/Linux/docs/LDP"
|
|
TARGET="_top"
|
|
>�</A
|
|
>, are an important source of
|
|
information. I suggest that you read Larry Greenfield's ``Linux User
|
|
Guide''---it's invaluable for the novice user.</P
|
|
><P
|
|
>And now, go ahead.</P
|
|
></DIV
|
|
><DIV
|
|
CLASS="SECT2"
|
|
><HR><H2
|
|
CLASS="SECT2"
|
|
><A
|
|
NAME="AEN47"
|
|
></A
|
|
>1.2. Comparing Commands and Files</H2
|
|
><P
|
|
>This table attempts to compare VMS' and Linux' most used commands. Please
|
|
keep in mind that the syntax is often very different; for more details,
|
|
refer to the following sections.</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>VMS Linux Notes
|
|
------------------------------------------------------------------------------
|
|
|
|
@COMMAND command must be executable
|
|
COPY file1 file2 cp file1 file2
|
|
CREATE/DIR [.dirname] mkdir dirname only one at a time
|
|
CREATE/DIR [.dir1.dir2] mkdirhier dir/name
|
|
DELETE filename rm filename
|
|
DIFF file1 file2 diff -c file1 file2
|
|
DIRECTORY ls
|
|
DIRECTORY [...]file find . -name file
|
|
DIRECTORY/FULL ls -al
|
|
EDIT filename vi filename, you won't like it
|
|
emacs filename, EDT compatible
|
|
jed filename ditto---my favourite
|
|
FORTRAN prog.for g77 prog.f, no need to do LINK
|
|
f77 prog.f,
|
|
fort77 prog.f
|
|
HELP command man command must specify `command'
|
|
info command ditto
|
|
LATEX file.tex latex file.tex
|
|
LOGIN.COM .bash_profile, `hidden' file
|
|
.bashrc ditto
|
|
LOGOUT.COM .bash_logout ditto
|
|
MAIL mail, crude
|
|
elm, much better
|
|
pine better still
|
|
mutt ditto
|
|
PRINT file.ps lpr file.ps
|
|
PRINT/QUEUE=laser file.ps lpr -Plaser file.ps
|
|
PHONE user talk user
|
|
RENAME file1 file2 mv file1 file2 not for multiple files
|
|
RUN progname progname
|
|
SEARCH file "pattern" grep pattern file
|
|
SET DEFAULT [-] cd ..
|
|
SET DEFAULT [.dir.name] cd dir/name
|
|
SET HOST hostname telnet hostname, not exactly the same
|
|
rlogin hostname
|
|
SET FILE/OWNER_UIC=joe chown joe file completely different
|
|
SET NOBROADCAST mesg
|
|
SET PASSWORD passwd
|
|
SET PROT=(perm) file chmod perm file completely different
|
|
SET TERMINAL export TERM= different syntax
|
|
SHOW DEFAULT pwd
|
|
SHOW DEVICE du, df
|
|
SHOW ENTRY lpq
|
|
SHOW PROCESS ps -ax
|
|
SHOW QUEUE lpq
|
|
SHOW SYSTEM top
|
|
SHOW TIME date
|
|
SHOW USERS w
|
|
STOP kill
|
|
STOP/QUEUE kill, for processes
|
|
lprm for print queues
|
|
SUBMIT command command &
|
|
SUBMIT/AFTER=time command at time command
|
|
TEX file.tex tex file.tex
|
|
TYPE/PAGE file more file
|
|
less file much better </PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
><P
|
|
>But of course it's not only a matter of different command names. Read on.</P
|
|
></DIV
|
|
></DIV
|
|
><DIV
|
|
CLASS="SECT1"
|
|
><HR><H1
|
|
CLASS="SECT1"
|
|
><A
|
|
NAME="SHORT-INTRO"
|
|
></A
|
|
>2. Short Intro</H1
|
|
><P
|
|
>This is what you absolutely need to know before logging in the first
|
|
time. Relax, it's not much.</P
|
|
><DIV
|
|
CLASS="SECT2"
|
|
><HR><H2
|
|
CLASS="SECT2"
|
|
><A
|
|
NAME="AEN56"
|
|
></A
|
|
>2.1. Files</H2
|
|
><P
|
|
> <P
|
|
></P
|
|
><UL
|
|
><LI
|
|
><P
|
|
> Under VMS filenames are in the form <TT
|
|
CLASS="LITERAL"
|
|
>filename.extension;version</TT
|
|
>.
|
|
Under Linux, the version number doesn't exist (big limitation, but see
|
|
Section <A
|
|
HREF="#NUMBERED-BACKUPS-UNDER-LINUX"
|
|
>Section 10.2</A
|
|
>); the filename
|
|
has normally a limit of 255 characters and can have as many dots as you
|
|
like. Example of filename: <TT
|
|
CLASS="LITERAL"
|
|
>This.is_a_FILEname.txt</TT
|
|
>. </P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> Linux distinguishes between upper case and lower case characters:
|
|
<TT
|
|
CLASS="LITERAL"
|
|
>FILENAME.txt</TT
|
|
> and <TT
|
|
CLASS="LITERAL"
|
|
>filename.txt</TT
|
|
> are two different files;
|
|
<TT
|
|
CLASS="LITERAL"
|
|
>ls</TT
|
|
> is a command, <TT
|
|
CLASS="LITERAL"
|
|
>LS</TT
|
|
> is not. </P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> A filename starting with a dot is a `hidden' file (that is,
|
|
it won't normally show up in dir listings), while filenames ending with a
|
|
tilde '<TT
|
|
CLASS="LITERAL"
|
|
>˜</TT
|
|
>' represent backup files.
|
|
</P
|
|
></LI
|
|
></UL
|
|
> </P
|
|
><P
|
|
>Now, a table to sum up how to translate commands from VMS to Linux:</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
> VMS Linux
|
|
---------------------------------------------------------------------
|
|
|
|
$ COPY file1.txt file2.txt $ cp file1.txt file2.txt
|
|
$ COPY [.dir]file.txt [] $ cp dir/file.txt .
|
|
$ COPY [.dir]file.txt [-] $ cp dir/file.txt ..
|
|
$ DELETE *.dat;* $ rm *dat
|
|
$ DIFF file1 file2 $ diff -c file1 file2
|
|
$ PRINT file $ lpr file
|
|
$ PRINT/queue=queuename file $ lpr -Pprintername file
|
|
$ SEARCH *.tex;* "geology" $ grep geology *tex</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
><P
|
|
>For other examples involving directories, see below; for details about
|
|
protections, ownership, and advanced topics, see Section <A
|
|
HREF="#ADVANCED-TOPICS"
|
|
>Section 8</A
|
|
>.</P
|
|
></DIV
|
|
><DIV
|
|
CLASS="SECT2"
|
|
><HR><H2
|
|
CLASS="SECT2"
|
|
><A
|
|
NAME="AEN79"
|
|
></A
|
|
>2.2. Directories</H2
|
|
><P
|
|
> <P
|
|
></P
|
|
><UL
|
|
><LI
|
|
><P
|
|
> Within the same node and device, directories names under VMS are in
|
|
the form <TT
|
|
CLASS="LITERAL"
|
|
>[top.dir.subdir]</TT
|
|
>; under Linux, <TT
|
|
CLASS="LITERAL"
|
|
>/top/dir/subdir/</TT
|
|
>. On
|
|
the top of the directory tree lies the so--called `root directory' called
|
|
<TT
|
|
CLASS="LITERAL"
|
|
>/</TT
|
|
>; underneath there are other directories like <TT
|
|
CLASS="LITERAL"
|
|
>/bin</TT
|
|
>,
|
|
<TT
|
|
CLASS="LITERAL"
|
|
>/usr</TT
|
|
>, <TT
|
|
CLASS="LITERAL"
|
|
>/tmp</TT
|
|
>, <TT
|
|
CLASS="LITERAL"
|
|
>/etc</TT
|
|
>, and others. </P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> The directory <TT
|
|
CLASS="LITERAL"
|
|
>/home</TT
|
|
> contains the so--called users' `home
|
|
directories': e.g. <TT
|
|
CLASS="LITERAL"
|
|
>/home/guido</TT
|
|
>, <TT
|
|
CLASS="LITERAL"
|
|
>/home/warner</TT
|
|
>, and so on.
|
|
When a user logs in, they start working in their home dir; it's the
|
|
equivalent of <TT
|
|
CLASS="LITERAL"
|
|
>SYS$LOGIN</TT
|
|
>. There's a shortcut for the home
|
|
directory: the tilde '<TT
|
|
CLASS="LITERAL"
|
|
>˜</TT
|
|
>'. So, <TT
|
|
CLASS="LITERAL"
|
|
>cd ˜/tmp</TT
|
|
> is the same
|
|
as, say, <TT
|
|
CLASS="LITERAL"
|
|
>cd /home/guido/tmp</TT
|
|
>. </P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> Directory names follow the same rules as file names. Furthermore,
|
|
each directory has two special entries: one is <TT
|
|
CLASS="LITERAL"
|
|
>.</TT
|
|
> and refers to the
|
|
directory itself (like <TT
|
|
CLASS="LITERAL"
|
|
>[]</TT
|
|
>), and <TT
|
|
CLASS="LITERAL"
|
|
>..</TT
|
|
> that refers to the parent
|
|
directory (like <TT
|
|
CLASS="LITERAL"
|
|
>[-]</TT
|
|
>). </P
|
|
></LI
|
|
></UL
|
|
>
|
|
</P
|
|
><P
|
|
>And now for some other examples:</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
> VMS Linux
|
|
---------------------------------------------------------------------
|
|
|
|
$ CREATE/DIR [.dirname] $ mkdir dirname
|
|
$ CREATE/DIR [.dir1.dir2.dir3] $ mkdirhier dir1/dir2/dir3
|
|
n/a $ rmdir dirname
|
|
(if dirname is empty)
|
|
$ rm -R dirname
|
|
$ DIRECTORY $ ls
|
|
$ DIRECTORY [...]file.*;* $ find . -name "file*"
|
|
$ SET DEF SYS$LOGIN $ cd
|
|
$ SET DEF [-] $ cd ..
|
|
$ SET DEF [top.dir.subdir] $ cd /top/dir/subdir
|
|
$ SET DEF [.dir.subdir] $ cd dir/subdir
|
|
$ SHOW DEF $ pwd </PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
><P
|
|
>For protections, ownership, and advanced topics, see Section <A
|
|
HREF="#ADVANCED-TOPICS"
|
|
>Section 8</A
|
|
>.</P
|
|
></DIV
|
|
><DIV
|
|
CLASS="SECT2"
|
|
><HR><H2
|
|
CLASS="SECT2"
|
|
><A
|
|
NAME="AEN112"
|
|
></A
|
|
>2.3. Programs</H2
|
|
><P
|
|
> <P
|
|
></P
|
|
><UL
|
|
><LI
|
|
><P
|
|
> Commands, compiled programs, and shell scripts (VMS' `command
|
|
files') don't have sort of mandatory extensions like <TT
|
|
CLASS="LITERAL"
|
|
>.EXE</TT
|
|
> or <TT
|
|
CLASS="LITERAL"
|
|
>.COM</TT
|
|
>
|
|
and can be called whatever you like. Executable files are marked by an
|
|
asterisk '<TT
|
|
CLASS="LITERAL"
|
|
>*</TT
|
|
>' when you issue <TT
|
|
CLASS="LITERAL"
|
|
>ls -F</TT
|
|
>. </P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> To run an executable file, just type its name (no <TT
|
|
CLASS="LITERAL"
|
|
>RUN
|
|
PROGRAM.EXE</TT
|
|
> or <TT
|
|
CLASS="LITERAL"
|
|
>@COMMAND</TT
|
|
>). Caveat: it's essential that the file be
|
|
located in a directory included in the <EM
|
|
>path of executables</EM
|
|
>, which is a
|
|
list of directories. Typically, the path includes dirs like <TT
|
|
CLASS="LITERAL"
|
|
>/bin</TT
|
|
>,
|
|
<TT
|
|
CLASS="LITERAL"
|
|
>/usr/bin</TT
|
|
>, <TT
|
|
CLASS="LITERAL"
|
|
>/usr/X11R6/bin</TT
|
|
>, and others. If you write your
|
|
own programs, put them in a directory you have included in the path (see how
|
|
in Section <A
|
|
HREF="#CONFIGURING"
|
|
>Section 9</A
|
|
>). As an alternative,
|
|
you may run a program specifying its complete path: e.g.,
|
|
<TT
|
|
CLASS="LITERAL"
|
|
>/home/guido/data/myprog</TT
|
|
>; or <TT
|
|
CLASS="LITERAL"
|
|
>./myprog</TT
|
|
>, if the current
|
|
directory isn't in the path. </P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> Command switches are obtained with <TT
|
|
CLASS="LITERAL"
|
|
>/OPTION=</TT
|
|
> under VMS, and
|
|
with <TT
|
|
CLASS="LITERAL"
|
|
>-switch</TT
|
|
> or <TT
|
|
CLASS="LITERAL"
|
|
>--switch</TT
|
|
> under Linux, where <TT
|
|
CLASS="LITERAL"
|
|
>switch</TT
|
|
> is a
|
|
letter, more letters combined, or a word. In particular, the switch <TT
|
|
CLASS="LITERAL"
|
|
>-R</TT
|
|
>
|
|
(recursive) of many Linux commands performs the same action as <TT
|
|
CLASS="LITERAL"
|
|
>[...]</TT
|
|
>
|
|
under VMS; </P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> You can issue several commands on the command line:
|
|
|
|
|
|
<TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="90%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>$ command1 ; command2 ; ... ; commandn</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
>
|
|
</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> Most of the flexibility of Linux comes from two features awkwardly
|
|
implemented or missing in VMS: I/O redirection and piping. (I have been told
|
|
that recent versions of DCL support redirection and piping, but I don't have
|
|
that version.) Redirection is a side feature under VMS (remember
|
|
the switch <TT
|
|
CLASS="LITERAL"
|
|
>/OUTPUT=</TT
|
|
> of many commands), or a fastidious process,
|
|
like:
|
|
|
|
|
|
<TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="90%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>$ DEFINE /USER SYS$OUTPUT OUT
|
|
$ DEFINE /USER SYS$INPUT IN
|
|
$ RUN PROG</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
>
|
|
|
|
|
|
which has the simple Linux (UNIX) equivalent:
|
|
|
|
|
|
<TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="90%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>$ prog < in > out</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
>
|
|
|
|
|
|
Piping is not readily available under VMS, but has a key role under UNIX. A
|
|
typical example:
|
|
|
|
|
|
<TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="90%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>$ myprog < datafile | filter_1 | filter_2 >> result.dat 2> errors.log &</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
>
|
|
|
|
|
|
which means: the program <TT
|
|
CLASS="LITERAL"
|
|
>myprog</TT
|
|
> gets its input from the file
|
|
<TT
|
|
CLASS="LITERAL"
|
|
>datafile</TT
|
|
> (via <TT
|
|
CLASS="LITERAL"
|
|
><</TT
|
|
>), its output is piped (via <TT
|
|
CLASS="LITERAL"
|
|
>|</TT
|
|
>) to
|
|
the program <TT
|
|
CLASS="LITERAL"
|
|
>filter_1</TT
|
|
> that takes it as input and processes it, the
|
|
resulting output is piped again to <TT
|
|
CLASS="LITERAL"
|
|
>filter_2</TT
|
|
> for further processing, the
|
|
final output is appended (via <TT
|
|
CLASS="LITERAL"
|
|
>>></TT
|
|
>) to the file <TT
|
|
CLASS="LITERAL"
|
|
>result.dat</TT
|
|
>,
|
|
and error messages are redirected (via <TT
|
|
CLASS="LITERAL"
|
|
>2></TT
|
|
>) onto the file
|
|
<TT
|
|
CLASS="LITERAL"
|
|
>errors.log</TT
|
|
>. All this in background (<TT
|
|
CLASS="LITERAL"
|
|
>&</TT
|
|
> at the end of the
|
|
command line). More about this in Section <A
|
|
HREF="#EXAMPLES"
|
|
>Section 11</A
|
|
>. </P
|
|
></LI
|
|
></UL
|
|
>
|
|
</P
|
|
><P
|
|
>For multitasking, `queues', and the like, see Section <A
|
|
HREF="#ADVANCED-TOPICS"
|
|
>Section 8</A
|
|
>.</P
|
|
></DIV
|
|
><DIV
|
|
CLASS="SECT2"
|
|
><HR><H2
|
|
CLASS="SECT2"
|
|
><A
|
|
NAME="QUICK-TOUR"
|
|
></A
|
|
>2.4. Quick Tour</H2
|
|
><P
|
|
>Now you are ready to try Linux out. Enter your login name and password
|
|
<EM
|
|
>exactly</EM
|
|
> as they are. For example, if your login name and password are
|
|
<TT
|
|
CLASS="LITERAL"
|
|
>john</TT
|
|
> and <TT
|
|
CLASS="LITERAL"
|
|
>My_PassWd</TT
|
|
>, <EM
|
|
>don't</EM
|
|
> type <TT
|
|
CLASS="LITERAL"
|
|
>John</TT
|
|
> or <TT
|
|
CLASS="LITERAL"
|
|
>my_passwd</TT
|
|
>.
|
|
Remember, UNIX distinguishes between capital and small letters.</P
|
|
><P
|
|
>Once you've logged in, you'll see a prompt; chances are it'll be something
|
|
like <TT
|
|
CLASS="LITERAL"
|
|
>machinename:$</TT
|
|
>. If you want to change the prompt or make
|
|
some programs start automatically, you'll have to edit a `hidden' file
|
|
called <TT
|
|
CLASS="LITERAL"
|
|
>.profile</TT
|
|
> or <TT
|
|
CLASS="LITERAL"
|
|
>.bash_profile</TT
|
|
> (see example in Section <A
|
|
HREF="#CONFIGURING"
|
|
>Section 9</A
|
|
>). This is the equivalent of
|
|
<TT
|
|
CLASS="LITERAL"
|
|
>LOGIN.COM</TT
|
|
>.</P
|
|
><P
|
|
>Pressing ALT--F1, ALT--F2, ... ALT--F6 switches between `virtual consoles'.
|
|
When one VC is busy with a full--screen application, you can flip over to
|
|
another and continue to work. Try and log in to another VC.</P
|
|
><P
|
|
>Now you may want to start X Window System (from now on, X). X is a graphic
|
|
environment very similar to DECWindows---actually, the latter derives from
|
|
the former. Type the command <TT
|
|
CLASS="LITERAL"
|
|
>startx</TT
|
|
> and wait a few seconds; most likely
|
|
you'll see an open <TT
|
|
CLASS="LITERAL"
|
|
>xterm</TT
|
|
> or equivalent terminal emulator, and possibly
|
|
a button bar. (It depends on how your sysadm configured your Linux box.)
|
|
Click on the desktop (try both mouse buttons) to see a menu.</P
|
|
><P
|
|
>While in X, to access the text mode (`console') sessions press
|
|
CTRL--ALT--F1 ... CTRL--ALT--F6. Try it. When in console, go back to X
|
|
pressing ALT--F7. To quit X, follow the menu instructions or press
|
|
CTRL--ALT--BS.</P
|
|
><P
|
|
>Type the following command to list your home dir contents, including the
|
|
hidden files:</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>$ ls -al</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
><P
|
|
>Press SHIFT--PAG UP to back-scroll. Now get help about the <TT
|
|
CLASS="LITERAL"
|
|
>ls</TT
|
|
> command
|
|
typing:</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>$ man ls</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
><P
|
|
>pressing 'q' to exit. To end the tour, type <TT
|
|
CLASS="LITERAL"
|
|
>exit</TT
|
|
> to quit your session.
|
|
If now you want to turn off your PC, press CTRL--ALT--DEL and wait a few
|
|
seconds (<EM
|
|
>never</EM
|
|
> switch off the PC while in Linux! You could damage the
|
|
filesystem.)</P
|
|
><P
|
|
>If you think you're ready to work, go ahead, but if I were you I'd jump
|
|
to Section <A
|
|
HREF="#ADVANCED-TOPICS"
|
|
>Section 8</A
|
|
>.</P
|
|
></DIV
|
|
></DIV
|
|
><DIV
|
|
CLASS="SECT1"
|
|
><HR><H1
|
|
CLASS="SECT1"
|
|
><A
|
|
NAME="EDITING-FILES"
|
|
></A
|
|
>3. Editing Files</H1
|
|
><P
|
|
>Linux doesn't have <TT
|
|
CLASS="LITERAL"
|
|
>EDT</TT
|
|
>, but there are scores of editors available. The
|
|
only one that's guaranteed to be included in every UNIX version is
|
|
<TT
|
|
CLASS="LITERAL"
|
|
>vi</TT
|
|
>---forget it, your sysadm must have installed something better.
|
|
Probably the most popular editor is <TT
|
|
CLASS="LITERAL"
|
|
>emacs</TT
|
|
>, which can emulate <TT
|
|
CLASS="LITERAL"
|
|
>EDT</TT
|
|
>
|
|
to a certain degree; <TT
|
|
CLASS="LITERAL"
|
|
>jed</TT
|
|
> is another editor that provides <TT
|
|
CLASS="LITERAL"
|
|
>EDT</TT
|
|
>
|
|
emulation.</P
|
|
><P
|
|
>These two editors are particularly useful for editing program sources, since
|
|
they have two features unknown to <TT
|
|
CLASS="LITERAL"
|
|
>EDT</TT
|
|
>: syntax hilighting and automatic
|
|
indentation. Moreover, you can compile your programs from within the editor
|
|
(command <TT
|
|
CLASS="LITERAL"
|
|
>ESC-X compile</TT
|
|
>); in case of a syntax error, the cursor will be
|
|
positioned on the offending line. I bet that you'll never want to use the
|
|
true blue <TT
|
|
CLASS="LITERAL"
|
|
>EDT</TT
|
|
> again.</P
|
|
><P
|
|
>If you have <TT
|
|
CLASS="LITERAL"
|
|
>emacs</TT
|
|
>: start it, then type <TT
|
|
CLASS="LITERAL"
|
|
>ESC-X edt-emulation-on</TT
|
|
>.
|
|
Pressing ALT--X or ESC-X is <TT
|
|
CLASS="LITERAL"
|
|
>emacs</TT
|
|
>' way of issuing commands, like
|
|
<TT
|
|
CLASS="LITERAL"
|
|
>EDT</TT
|
|
>'s CTRL--Z. From now on, <TT
|
|
CLASS="LITERAL"
|
|
>emacs</TT
|
|
> acts like <TT
|
|
CLASS="LITERAL"
|
|
>EDT</TT
|
|
> apart from a
|
|
few commands. Differences:</P
|
|
><P
|
|
> <P
|
|
></P
|
|
><UL
|
|
><LI
|
|
><P
|
|
> <EM
|
|
>don't</EM
|
|
> press CTRL--Z to issue commands (if you did, you stopped
|
|
<TT
|
|
CLASS="LITERAL"
|
|
>emacs</TT
|
|
>. Type <TT
|
|
CLASS="LITERAL"
|
|
>fg</TT
|
|
> to resume it); </P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> there's an extensive on-line help. Press CTRL-H ?, or CTRL-H T to
|
|
start a tutorial; </P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> to save a file, press CTRL-X CTRL-S; </P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> to exit, press CTRL-X CTRL-C; </P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> to insert a new file in a buffer, press CTRL-X CTRL-F, then
|
|
CTRL-X B to switch among buffers. </P
|
|
></LI
|
|
></UL
|
|
> </P
|
|
><P
|
|
>If you have <TT
|
|
CLASS="LITERAL"
|
|
>jed</TT
|
|
>: ask your sysadm to configure <TT
|
|
CLASS="LITERAL"
|
|
>jed</TT
|
|
> properly.
|
|
Emulation is already on when you start it; use the normal keypad keys, and
|
|
press CTRL--H CTRL--H or CTRL-? to get help. Commands are issued in the same
|
|
way as <TT
|
|
CLASS="LITERAL"
|
|
>emacs</TT
|
|
>'. In addition, there are some handy key bindings missing
|
|
in the original <TT
|
|
CLASS="LITERAL"
|
|
>EDT</TT
|
|
>; key bindings can also be tailored to your own
|
|
taste. Ask your sysadm.</P
|
|
><P
|
|
>In alternative, you may use another editor with a completely different
|
|
interface. <TT
|
|
CLASS="LITERAL"
|
|
>emacs</TT
|
|
> in native mode is an obvious choice; another popular
|
|
editor is <TT
|
|
CLASS="LITERAL"
|
|
>joe</TT
|
|
>, which can emulate other editors like <TT
|
|
CLASS="LITERAL"
|
|
>emacs</TT
|
|
> itself
|
|
(being even easier to use) or the DOS editor. Invoke the editor as
|
|
<TT
|
|
CLASS="LITERAL"
|
|
>jmacs</TT
|
|
> or <TT
|
|
CLASS="LITERAL"
|
|
>jstar</TT
|
|
> and press, respectively, CTRL-X H or CTRL-J to get
|
|
online help. <TT
|
|
CLASS="LITERAL"
|
|
>emacs</TT
|
|
> and <TT
|
|
CLASS="LITERAL"
|
|
>jed</TT
|
|
> are <EM
|
|
>much</EM
|
|
> more powerful than good
|
|
ol' <TT
|
|
CLASS="LITERAL"
|
|
>EDT</TT
|
|
>.</P
|
|
></DIV
|
|
><DIV
|
|
CLASS="SECT1"
|
|
><HR><H1
|
|
CLASS="SECT1"
|
|
><A
|
|
NAME="TEXING"
|
|
></A
|
|
>4. TeXing</H1
|
|
><P
|
|
>TeX and LaTeX are identical to their VMS counterparts---only quicker :-),
|
|
but the tools to handle the <TT
|
|
CLASS="LITERAL"
|
|
>.dvi</TT
|
|
> and <TT
|
|
CLASS="LITERAL"
|
|
>.ps</TT
|
|
> files are superior:</P
|
|
><P
|
|
> <P
|
|
></P
|
|
><UL
|
|
><LI
|
|
><P
|
|
> to run a TeX file through TeX, do as usual: <TT
|
|
CLASS="LITERAL"
|
|
>tex file.tex</TT
|
|
>; </P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> to turn a <TT
|
|
CLASS="LITERAL"
|
|
>.dvi</TT
|
|
> file into a <TT
|
|
CLASS="LITERAL"
|
|
>.ps</TT
|
|
> file, type
|
|
<TT
|
|
CLASS="LITERAL"
|
|
>dvips -o filename.ps filename.dvi</TT
|
|
>; </P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> to visualize a <TT
|
|
CLASS="LITERAL"
|
|
>.dvi</TT
|
|
> file, type within an X session:
|
|
<TT
|
|
CLASS="LITERAL"
|
|
>xdvi filename.dvi &</TT
|
|
>. Click on the page to magnify. This program
|
|
is smart: if you edit and run TeX producing newer versions of the <TT
|
|
CLASS="LITERAL"
|
|
>.dvi</TT
|
|
>
|
|
file, <TT
|
|
CLASS="LITERAL"
|
|
>xdvi</TT
|
|
> will update it automatically; </P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> to visualize a <TT
|
|
CLASS="LITERAL"
|
|
>.ps</TT
|
|
> file, type within an X session: <TT
|
|
CLASS="LITERAL"
|
|
>ghostview
|
|
filename.ps &</TT
|
|
>. Click on the page to magnify. The whole document or
|
|
selected pages can be printed. A newer and better program is <TT
|
|
CLASS="LITERAL"
|
|
>gv</TT
|
|
>. </P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> to print the <TT
|
|
CLASS="LITERAL"
|
|
>.ps</TT
|
|
>: usually the command <TT
|
|
CLASS="LITERAL"
|
|
>lpr mypaper.ps</TT
|
|
> will
|
|
do, but if the PostScript printer is called, say, `ps' (ask your
|
|
sysadm) you'll do: <TT
|
|
CLASS="LITERAL"
|
|
>lpr -Pps mypaper.ps</TT
|
|
>. For more information
|
|
about print queues, go to Section <A
|
|
HREF="#PRINT-QUEUES"
|
|
>Section 8.4</A
|
|
>. </P
|
|
></LI
|
|
></UL
|
|
> </P
|
|
></DIV
|
|
><DIV
|
|
CLASS="SECT1"
|
|
><HR><H1
|
|
CLASS="SECT1"
|
|
><A
|
|
NAME="PROGRAMMING"
|
|
></A
|
|
>5. Programming</H1
|
|
><P
|
|
>Programming under Linux is <EM
|
|
>much</EM
|
|
> better: there are lots of tools that
|
|
make programming easier and quicker. For instance, the drudgery of
|
|
editing--saving--exiting--compiling--re-editing can be cut short by using
|
|
editors like <TT
|
|
CLASS="LITERAL"
|
|
>emacs</TT
|
|
> or <TT
|
|
CLASS="LITERAL"
|
|
>jed</TT
|
|
>, as seen above.</P
|
|
><DIV
|
|
CLASS="SECT2"
|
|
><HR><H2
|
|
CLASS="SECT2"
|
|
><A
|
|
NAME="AEN284"
|
|
></A
|
|
>5.1. Fortran</H2
|
|
><P
|
|
>Not substantial differences here, but note that at the time of writing the
|
|
available (free) compilers are not 100% compatible with VMS'; expect
|
|
some minor quirks. (It's actually the VMS compiler which has non-standard
|
|
extensions.) See <TT
|
|
CLASS="LITERAL"
|
|
>/usr/doc/g77/DOC</TT
|
|
> or <TT
|
|
CLASS="LITERAL"
|
|
>/usr/doc/f2c/f2c.ps</TT
|
|
>
|
|
for details.</P
|
|
><P
|
|
>Your sysadm has installed a native compiler called <TT
|
|
CLASS="LITERAL"
|
|
>g77</TT
|
|
> (good but, as of
|
|
version 0.5.21, still not perfectly compatible with DEC Fortran) or possibly
|
|
the Fortran to C translator, <TT
|
|
CLASS="LITERAL"
|
|
>f2c</TT
|
|
>, and one of the front-ends that make it
|
|
mimic a native compiler. In my experience, the package <TT
|
|
CLASS="LITERAL"
|
|
>yaf77</TT
|
|
> is the
|
|
one that provides best results.</P
|
|
><P
|
|
>To compile a Fortran program with <TT
|
|
CLASS="LITERAL"
|
|
>g77</TT
|
|
>, edit the source, save it with
|
|
extension <TT
|
|
CLASS="LITERAL"
|
|
>.f</TT
|
|
>, then do:</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>$ g77 myprog.f</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
><P
|
|
>which creates by default an executable called <TT
|
|
CLASS="LITERAL"
|
|
>a.out</TT
|
|
> (you don't have
|
|
to link anything). To give the executable a different name and do some
|
|
optimisation:</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>$ g77 -O2 -o myprog myprog.f</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
><P
|
|
>Beware of optimisations! Ask your sysadm to read the documentation that
|
|
comes with the compiler and tell you if there are any problems.</P
|
|
><P
|
|
>To compile a subroutine:</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>$ g77 -c mysub.f</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
><P
|
|
>This creates a file <TT
|
|
CLASS="LITERAL"
|
|
>mysub.o</TT
|
|
>. To link this subroutine to a program,
|
|
you'll do</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>$ g77 -o myprog myprog.f mysub.o</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
><P
|
|
>If you have many external subroutines and you want to make a library, do the
|
|
following:</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>$ cd subroutines/
|
|
$ cat *f >mylib.f ; g77 -c mylib.f</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
><P
|
|
>This will create <TT
|
|
CLASS="LITERAL"
|
|
>mylib.o</TT
|
|
> that you can link to your programs.</P
|
|
><P
|
|
>Finally, to link an external library called, say, <TT
|
|
CLASS="LITERAL"
|
|
>libdummy.so</TT
|
|
>:</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>$ g77 -o myprog myprog.f -ldummy</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
><P
|
|
>If you have <TT
|
|
CLASS="LITERAL"
|
|
>f2c</TT
|
|
>, you only have to use <TT
|
|
CLASS="LITERAL"
|
|
>f77</TT
|
|
> or <TT
|
|
CLASS="LITERAL"
|
|
>fort77</TT
|
|
> instead
|
|
of <TT
|
|
CLASS="LITERAL"
|
|
>g77</TT
|
|
>.</P
|
|
><P
|
|
>Another useful programming tool is <TT
|
|
CLASS="LITERAL"
|
|
>make</TT
|
|
>, described below.</P
|
|
></DIV
|
|
><DIV
|
|
CLASS="SECT2"
|
|
><HR><H2
|
|
CLASS="SECT2"
|
|
><A
|
|
NAME="AEN326"
|
|
></A
|
|
>5.2. Using <TT
|
|
CLASS="LITERAL"
|
|
>make</TT
|
|
></H2
|
|
><P
|
|
>The utility <TT
|
|
CLASS="LITERAL"
|
|
>make</TT
|
|
> is a tool to handle the compilation of programs that
|
|
are split into several source files. The VMS counterparts are <TT
|
|
CLASS="LITERAL"
|
|
>MMS</TT
|
|
>
|
|
and <TT
|
|
CLASS="LITERAL"
|
|
>MMK</TT
|
|
>, which have a different syntax.</P
|
|
><P
|
|
>Let's suppose you have source files containing your routines, <TT
|
|
CLASS="LITERAL"
|
|
>file_1.f,
|
|
file_2.f, file_3.f</TT
|
|
>, and a source file of the main program that uses the
|
|
routines, <TT
|
|
CLASS="LITERAL"
|
|
>myprog.f</TT
|
|
>. If you compile your program manually, whenever you
|
|
modify one of the source files you have to figure out which file depends on
|
|
which, which file to recompile first, and so on.</P
|
|
><P
|
|
>Instead of getting mad, you can write a `makefile'. This is a text file
|
|
containing the dependencies between your sources: when one is modified, only
|
|
the ones that depend on the modified file will be recompiled.</P
|
|
><P
|
|
>In our example, you'd write a makefile like this:</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="0"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="PROGRAMLISTING"
|
|
> # This is makefile
|
|
# Press the <TAB> key where you see <TAB>!
|
|
# It's important: don't use spaces instead.
|
|
|
|
myprog: myprog.o file_1.o file_2.o file_3.o
|
|
<TAB>g77 -o myprog myprog.o file_1.o file_2.o file_3.o
|
|
# myprog depends on four object files
|
|
|
|
myprog.o: myprog.f
|
|
<TAB>g77 -c myprog.f
|
|
# myprog.o depends on its source file
|
|
|
|
file_1.o: file_1.f
|
|
<TAB>g77 -c file_1.f
|
|
# file_1.o depends on its source file
|
|
|
|
file_2.o: file_2.f file_1.o
|
|
<TAB>g77 -c file_2.f file_1.o
|
|
# file_2.o depends on its source file and an object file
|
|
|
|
file_3.o: file_3.f file_2.o
|
|
<TAB>g77 -c file_3.f file_2.o
|
|
# file_3.o depends on its source file and an object file
|
|
|
|
# end of makefile.</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
><P
|
|
>Save this file as <TT
|
|
CLASS="LITERAL"
|
|
>Makefile</TT
|
|
> and type <TT
|
|
CLASS="LITERAL"
|
|
>make</TT
|
|
> to compile your program;
|
|
alternatively, save it as <TT
|
|
CLASS="LITERAL"
|
|
>myprog.mak</TT
|
|
> and type <TT
|
|
CLASS="LITERAL"
|
|
>make -f myprog.mak</TT
|
|
>.
|
|
And of course, RMP.</P
|
|
></DIV
|
|
><DIV
|
|
CLASS="SECT2"
|
|
><HR><H2
|
|
CLASS="SECT2"
|
|
><A
|
|
NAME="AEN345"
|
|
></A
|
|
>5.3. Shell Scripts</H2
|
|
><P
|
|
>Shell scripts are the equivalent of VMS' command files, and allow for very
|
|
powerful constructs.</P
|
|
><P
|
|
>To write a script, all you have to do is write a standard ASCII file
|
|
containing the commands, save it, then make it executable with the
|
|
command <TT
|
|
CLASS="LITERAL"
|
|
>chmod +x <scriptfile></TT
|
|
>. To execute it, type its name.</P
|
|
><P
|
|
>Writing scripts under <TT
|
|
CLASS="LITERAL"
|
|
>bash</TT
|
|
> is such a vast subject it would require a
|
|
book by itself, and I will not delve into the topic any further. I'll just
|
|
give you a more-or-less comprehensive and (hopefully) useful example you can
|
|
extract some basic rules from.</P
|
|
><P
|
|
>EXAMPLE: sample.sh</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="0"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="PROGRAMLISTING"
|
|
>#!/bin/sh
|
|
# sample.sh
|
|
# I am a comment
|
|
# don't change the first line, it must be there
|
|
echo "This system is: `uname -a`" # use the output of the command
|
|
echo "My name is $0" # built-in variables
|
|
echo "You gave me the following $# parameters: "$*
|
|
echo "First parameter is: "$1
|
|
echo -n "What's your name? " ; read your_name
|
|
echo notice the difference: "hi $your_name" # quoting with "
|
|
echo notice the difference: 'hi $your_name' # quoting with '
|
|
DIRS=0 ; FILES=0
|
|
for file in `ls .` ; do
|
|
if [ -d ${file} ] ; then # if file is a directory
|
|
DIRS=`expr $DIRS + 1` # this means DIRS = DIRS + 1
|
|
elif [ -f ${file} ] ; then
|
|
FILES=`expr $FILES + 1`
|
|
fi
|
|
case ${file} in
|
|
*.gif|*jpg) echo "${file}: graphic file" ;;
|
|
*.txt|*.tex) echo "${file}: text file" ;;
|
|
*.c|*.f|*.for) echo "${file}: source file" ;;
|
|
*) echo "${file}: generic file" ;;
|
|
esac
|
|
done
|
|
echo "there are ${DIRS} directories and ${FILES} files"
|
|
ls | grep "ZxY--!!!WKW"
|
|
if [ $? != 0 ] ; then # exit code of last command
|
|
echo "ZxY--!!!WKW not found"
|
|
fi
|
|
echo "enough... type 'man bash' if you want more info." </PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
></DIV
|
|
><DIV
|
|
CLASS="SECT2"
|
|
><HR><H2
|
|
CLASS="SECT2"
|
|
><A
|
|
NAME="C"
|
|
></A
|
|
>5.4. C</H2
|
|
><P
|
|
>Linux is an excellent environment to program in C. Taken for granted that
|
|
you know C, here are a couple of guidelines. To compile your standard
|
|
<TT
|
|
CLASS="LITERAL"
|
|
>hello.c</TT
|
|
> you'll use the <TT
|
|
CLASS="LITERAL"
|
|
>gcc</TT
|
|
> compiler, which comes as part of Linux
|
|
and has the same syntax as <TT
|
|
CLASS="LITERAL"
|
|
>g77</TT
|
|
>:</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>$ gcc -O2 -o hello hello.c</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
><P
|
|
>To link a library to a program, add the switch <TT
|
|
CLASS="LITERAL"
|
|
>-l<libname></TT
|
|
>.
|
|
For example, to link the math library and optimize do</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>$ gcc -O2 -o mathprog mathprog.c -lm</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
><P
|
|
>(The <TT
|
|
CLASS="LITERAL"
|
|
>-l<libname></TT
|
|
> switch forces <TT
|
|
CLASS="LITERAL"
|
|
>gcc</TT
|
|
> to link the library
|
|
<TT
|
|
CLASS="LITERAL"
|
|
>/usr/lib/lib<libname>.a</TT
|
|
>; so <TT
|
|
CLASS="LITERAL"
|
|
>-lm</TT
|
|
> links
|
|
<TT
|
|
CLASS="LITERAL"
|
|
>/usr/lib/libm.a</TT
|
|
>).</P
|
|
><P
|
|
>When your program is made of several source files, you'll need to use the
|
|
utility <TT
|
|
CLASS="LITERAL"
|
|
>make</TT
|
|
> described above. Just use <TT
|
|
CLASS="LITERAL"
|
|
>gcc</TT
|
|
> and C source files in
|
|
the makefile.</P
|
|
><P
|
|
>You can invoke some help about the C functions, that are covered by man
|
|
pages, section 3; for example,</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>$ man 3 printf</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
><P
|
|
>There are lots of libraries available out there; among the first you'll want
|
|
to use are <TT
|
|
CLASS="LITERAL"
|
|
>ncurses</TT
|
|
>, to handle text mode effects, and <TT
|
|
CLASS="LITERAL"
|
|
>svgalib</TT
|
|
>, to
|
|
do graphics.</P
|
|
></DIV
|
|
></DIV
|
|
><DIV
|
|
CLASS="SECT1"
|
|
><HR><H1
|
|
CLASS="SECT1"
|
|
><A
|
|
NAME="GRAPHICS"
|
|
></A
|
|
>6. Graphics</H1
|
|
><P
|
|
>Among the scores of graphic packages available, <TT
|
|
CLASS="LITERAL"
|
|
>gnuplot</TT
|
|
> stands out
|
|
for its power and ease of use. Go to X and type <TT
|
|
CLASS="LITERAL"
|
|
>gnuplot</TT
|
|
>, and have
|
|
two sample data files ready: <TT
|
|
CLASS="LITERAL"
|
|
>2D-data.dat</TT
|
|
> (two data per line), and
|
|
<TT
|
|
CLASS="LITERAL"
|
|
>3D-data.dat</TT
|
|
> (three data per line).</P
|
|
><P
|
|
>Examples of 2-D graphs:</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>gnuplot> set title "my first graph"
|
|
gnuplot> plot '2D-data.dat'
|
|
gnuplot> plot '2D-data.dat' with linespoints
|
|
gnuplot> plot '2D-data.dat', sin(x)
|
|
gnuplot> plot [-5:10] '2D-data.dat'</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
><P
|
|
>Example of 3-D graphs (each `row' of X values is followed by a blank
|
|
line):</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>gnuplot> set parametric ; set hidden3d ; set contour
|
|
gnuplot> splot '3D-data.dat' using 1:2:3 with linespoints</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
><P
|
|
>A single-column datafile (e.g., a time series) can also be plotted as a 2-D
|
|
graph:</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>gnuplot> plot [-5:15] '2D-data-1col.dat' with linespoints</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
><P
|
|
>or as a 3-D graph (blank lines in the datafile, as above):</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>gnuplot> set noparametric ; set hidden3d
|
|
gnuplot> splot '3D-data-1col.dat' using 1 with linespoints</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
><P
|
|
>To print a graph: if the command to print on your Postscript printer is
|
|
<TT
|
|
CLASS="LITERAL"
|
|
>lpr -Pps file.ps</TT
|
|
>, issue:</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>gnuplot> set term post
|
|
gnuplot> set out '| lpr -Pps'
|
|
gnuplot> replot</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
><P
|
|
>then type <TT
|
|
CLASS="LITERAL"
|
|
>set term x11</TT
|
|
> to restore. Don't get confused---the last print
|
|
will come out only when you quit <TT
|
|
CLASS="LITERAL"
|
|
>gnuplot</TT
|
|
>.</P
|
|
><P
|
|
>For more info, type <TT
|
|
CLASS="LITERAL"
|
|
>help</TT
|
|
> or see the examples in directory
|
|
<TT
|
|
CLASS="LITERAL"
|
|
>/usr/lib/gnuplot/demos/</TT
|
|
>, if you have it.</P
|
|
></DIV
|
|
><DIV
|
|
CLASS="SECT1"
|
|
><HR><H1
|
|
CLASS="SECT1"
|
|
><A
|
|
NAME="MAIL-AND-INTERNET-TOOLS"
|
|
></A
|
|
>7. Mail and Internet Tools</H1
|
|
><P
|
|
>Since Internet was born on UNIX machines, you find plenty of nice and
|
|
easy-to-use applications under Linux. Here are just some:</P
|
|
><P
|
|
> <P
|
|
></P
|
|
><UL
|
|
><LI
|
|
><P
|
|
> <EM
|
|
>Mail</EM
|
|
>: use <TT
|
|
CLASS="LITERAL"
|
|
>elm</TT
|
|
> or <TT
|
|
CLASS="LITERAL"
|
|
>pine</TT
|
|
> to handle your email; both
|
|
programs have on-line help. For short messages, you could use <TT
|
|
CLASS="LITERAL"
|
|
>mail</TT
|
|
>, as
|
|
in <TT
|
|
CLASS="LITERAL"
|
|
>mail -s "hello mate" user@somewhere < msg.txt</TT
|
|
>. You may like programs
|
|
like <TT
|
|
CLASS="LITERAL"
|
|
>xmail</TT
|
|
> or some such. </P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> <EM
|
|
>Newsgroups</EM
|
|
>: use <TT
|
|
CLASS="LITERAL"
|
|
>tin</TT
|
|
> or <TT
|
|
CLASS="LITERAL"
|
|
>slrn</TT
|
|
>, both very intuitive and
|
|
self-explanatory. </P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> <EM
|
|
>ftp</EM
|
|
>: apart from the usual character-based <TT
|
|
CLASS="LITERAL"
|
|
>ftp</TT
|
|
>, ask your
|
|
sysadm to install the full-screen <TT
|
|
CLASS="LITERAL"
|
|
>ncftp</TT
|
|
> or a graphical ftp client like
|
|
<TT
|
|
CLASS="LITERAL"
|
|
>xftp</TT
|
|
>. </P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> <EM
|
|
>WWW</EM
|
|
>: the ubiquitous <TT
|
|
CLASS="LITERAL"
|
|
>netscape</TT
|
|
>, or <TT
|
|
CLASS="LITERAL"
|
|
>xmosaic</TT
|
|
>,
|
|
<TT
|
|
CLASS="LITERAL"
|
|
>chimera</TT
|
|
>, and <TT
|
|
CLASS="LITERAL"
|
|
>arena</TT
|
|
> are graphical web browsers; a character-based
|
|
one is <TT
|
|
CLASS="LITERAL"
|
|
>lynx</TT
|
|
>, quick and effective. </P
|
|
></LI
|
|
></UL
|
|
> </P
|
|
></DIV
|
|
><DIV
|
|
CLASS="SECT1"
|
|
><HR><H1
|
|
CLASS="SECT1"
|
|
><A
|
|
NAME="ADVANCED-TOPICS"
|
|
></A
|
|
>8. Advanced Topics</H1
|
|
><P
|
|
>Here the game gets tough. Learn these features, then you'll be ready to say
|
|
that you `know something about Linux' ;-)</P
|
|
><DIV
|
|
CLASS="SECT2"
|
|
><HR><H2
|
|
CLASS="SECT2"
|
|
><A
|
|
NAME="PERMISSIONS"
|
|
></A
|
|
>8.1. Permissions and Ownership</H2
|
|
><P
|
|
>Files and directories have permissions (`protections') and ownership, just
|
|
like under VMS. If you can't run a program, or can't modify a file, or can't
|
|
access a directory, it's because you don't have the permission to do so,
|
|
and/or because the file doesn't belong to you. Let's have a look at the
|
|
following example:</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>$ ls -l /bin/ls
|
|
-rwxr-xr-x 1 root bin 27281 Aug 15 1995 /bin/ls*</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
><P
|
|
>The first field shows the permissions of the file <TT
|
|
CLASS="LITERAL"
|
|
>ls</TT
|
|
> (owner root,
|
|
group bin). There are three types of ownership: owner, group, and others
|
|
(similar to VMS owner, group, world), and three types of permissions:
|
|
read, write (and delete), and execute.</P
|
|
><P
|
|
>From left to right, <TT
|
|
CLASS="LITERAL"
|
|
>-</TT
|
|
> is the file type (<TT
|
|
CLASS="LITERAL"
|
|
>-</TT
|
|
> = ordinary file, <TT
|
|
CLASS="LITERAL"
|
|
>d</TT
|
|
>
|
|
= directory, <TT
|
|
CLASS="LITERAL"
|
|
>l</TT
|
|
> = link, etc); <TT
|
|
CLASS="LITERAL"
|
|
>rwx</TT
|
|
> are the permissions for the file
|
|
owner (read, write, execute); <TT
|
|
CLASS="LITERAL"
|
|
>r-x</TT
|
|
> are the permissions for the group of
|
|
the file owner (read, execute); <TT
|
|
CLASS="LITERAL"
|
|
>r-x</TT
|
|
> are the permissions for all other
|
|
users (read, execute).</P
|
|
><P
|
|
>To change a file's permissions:</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>$ chmod <whoXperm> <file></PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
><P
|
|
>where who is <TT
|
|
CLASS="LITERAL"
|
|
>u</TT
|
|
> (user, that is owner), <TT
|
|
CLASS="LITERAL"
|
|
>g</TT
|
|
> (group), <TT
|
|
CLASS="LITERAL"
|
|
>o</TT
|
|
> (other),
|
|
X is either <TT
|
|
CLASS="LITERAL"
|
|
>+</TT
|
|
> or <TT
|
|
CLASS="LITERAL"
|
|
>-</TT
|
|
>, perm is <TT
|
|
CLASS="LITERAL"
|
|
>r</TT
|
|
> (read), <TT
|
|
CLASS="LITERAL"
|
|
>w</TT
|
|
> (write), or
|
|
<TT
|
|
CLASS="LITERAL"
|
|
>x</TT
|
|
> (execute). Examples:</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>$ chmod u+x file</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
><P
|
|
>this sets the execute permission for the file owner. Shortcut:
|
|
<TT
|
|
CLASS="LITERAL"
|
|
>chmod +x file</TT
|
|
>.</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>$ chmod go-wx file</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
><P
|
|
>this removes write and execute permission for everyone except the owner.</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>$ chmod ugo+rwx file</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
><P
|
|
>this gives everyone read, write, and execute permission. </P
|
|
><P
|
|
>A shorter way to refer to permissions is with numbers: <TT
|
|
CLASS="LITERAL"
|
|
>rwxr-xr-x</TT
|
|
> can be
|
|
expressed as 755 (every letter corresponds to a bit: <TT
|
|
CLASS="LITERAL"
|
|
>---</TT
|
|
> is 0,
|
|
<TT
|
|
CLASS="LITERAL"
|
|
>--x</TT
|
|
> is 1, <TT
|
|
CLASS="LITERAL"
|
|
>-w-</TT
|
|
> is 2...).</P
|
|
><P
|
|
>For a directory, <TT
|
|
CLASS="LITERAL"
|
|
>rx</TT
|
|
> means that you can <TT
|
|
CLASS="LITERAL"
|
|
>cd</TT
|
|
> to that directory, and
|
|
<TT
|
|
CLASS="LITERAL"
|
|
>w</TT
|
|
> means that you can delete a file in the directory (according to the
|
|
file's permissions, of course), or the directory itself. All this is only
|
|
part of the matter---RMP.</P
|
|
><P
|
|
>To change a file's owner:</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>$ chown username file</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
><P
|
|
>To sum up, a table:</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>VMS Linux Notes
|
|
------------------------------------------------------------------------------
|
|
|
|
SET PROT=(O:RW) file.txt $ chmod u+rw file.txt
|
|
$ chmod 600 file.txt
|
|
SET PROT=(O:RWED,W) file $ chmod u+rwx file
|
|
$ chmod 700 file
|
|
SET PROT=(O:RWED,W:RE) file $ chmod 755 file
|
|
SET PROT=(O:RW,G:RW,W) file $ chmod 660 file
|
|
SET FILE/OWNER_UIC=JOE file $ chown joe file
|
|
SET DIR/OWNER_UIC=JOE [.dir] $ chown joe dir/</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
></DIV
|
|
><DIV
|
|
CLASS="SECT2"
|
|
><HR><H2
|
|
CLASS="SECT2"
|
|
><A
|
|
NAME="MULTITASKING"
|
|
></A
|
|
>8.2. Multitasking: Processes and Jobs</H2
|
|
><P
|
|
>More about running programs. There are no `batch queues' under Linux as
|
|
you're used to; multitasking is handled very differently. Again, this is
|
|
what the typical command line looks like:</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>$ command -s1 -s2 ... -sn par1 par2 ... parn < input > output &</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
><P
|
|
>where <TT
|
|
CLASS="LITERAL"
|
|
>-s1</TT
|
|
>, ..., <TT
|
|
CLASS="LITERAL"
|
|
>-sn</TT
|
|
> are the program switches,
|
|
<TT
|
|
CLASS="LITERAL"
|
|
>par1</TT
|
|
>, ..., <TT
|
|
CLASS="LITERAL"
|
|
>parn</TT
|
|
> are the program parameters.</P
|
|
><P
|
|
>Now let's see how multitasking works. Programs, running in foreground or
|
|
background, are called `processes'.</P
|
|
><P
|
|
> <P
|
|
></P
|
|
><UL
|
|
><LI
|
|
><P
|
|
> To launch a process in background:
|
|
|
|
<TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="90%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>$ progname [-switches] [parameters] [< input] [> output] &
|
|
[1] 234</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
>
|
|
|
|
the shell tells you what the `job number' (the first digit; see below) and
|
|
PID (Process IDentifier) of the process are. Each process is identified
|
|
by its PID. </P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> To see how many processes there are:
|
|
|
|
<TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="90%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>$ ps -ax</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
>
|
|
|
|
This will output a list of currently running processes. </P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> To kill a process:
|
|
|
|
<TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="90%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>$ kill <PID></PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
>
|
|
|
|
You may need to kill a process when you don't know how to quit it
|
|
the right way... ;-). Sometimes, a process will only be killed by
|
|
one of the following:
|
|
|
|
<TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="90%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>$ kill -15 <PID>
|
|
$ kill -9 <PID></PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
>
|
|
</P
|
|
></LI
|
|
></UL
|
|
> </P
|
|
><P
|
|
>In addition to this, the shell allows you to stop or temporarily suspend a
|
|
process, send a process to background, and bring a process from background
|
|
to foreground. In this context, processes are called `jobs'.</P
|
|
><P
|
|
> <P
|
|
></P
|
|
><UL
|
|
><LI
|
|
><P
|
|
> To see how many jobs there are:
|
|
|
|
<TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="90%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>$ jobs</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
>
|
|
|
|
jobs are identified by the numbers the shell gives them, not by their PID. </P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> To stop a process running in foreground:
|
|
|
|
<TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="90%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>$ CTRL-C</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
>
|
|
|
|
(it doesn't always work) </P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> To suspend a process running in foreground:
|
|
|
|
<TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="90%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>$ CTRL-Z</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
>
|
|
|
|
(ditto) </P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> To send a suspended process into background (it becomes a job):
|
|
|
|
<TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="90%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>$ bg <job></PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
>
|
|
</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> To bring a job to foreground:
|
|
|
|
<TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="90%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>$ fg <job></PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
>
|
|
</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> To kill a job:
|
|
|
|
<TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="90%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>$ kill <%job></PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
>
|
|
</P
|
|
></LI
|
|
></UL
|
|
> </P
|
|
></DIV
|
|
><DIV
|
|
CLASS="SECT2"
|
|
><HR><H2
|
|
CLASS="SECT2"
|
|
><A
|
|
NAME="AEN542"
|
|
></A
|
|
>8.3. Files, Revisited</H2
|
|
><P
|
|
>More information about files.</P
|
|
><P
|
|
> <P
|
|
></P
|
|
><UL
|
|
><LI
|
|
><P
|
|
> <EM
|
|
>stdin, stdout, stderr</EM
|
|
>: under UNIX, every system component is
|
|
treated as if it were a file. Commands and programs get their input from a
|
|
`file' called <TT
|
|
CLASS="LITERAL"
|
|
>stdin</TT
|
|
> (standard input; usually, the keyboard), put their
|
|
output on a `file' called <TT
|
|
CLASS="LITERAL"
|
|
>stdout</TT
|
|
> (usually, the screen), and error
|
|
messages go to a `file' called <TT
|
|
CLASS="LITERAL"
|
|
>stderr</TT
|
|
> (usually, the screen).
|
|
|
|
Using <TT
|
|
CLASS="LITERAL"
|
|
><</TT
|
|
> and <TT
|
|
CLASS="LITERAL"
|
|
>></TT
|
|
> you redirect input and output to a different
|
|
file. Moreover, <TT
|
|
CLASS="LITERAL"
|
|
>>></TT
|
|
> appends the output to a file instead of
|
|
overwriting it; <TT
|
|
CLASS="LITERAL"
|
|
>2></TT
|
|
> redirects error messages (stderr); 2>&1
|
|
redirects stderr to stdout, while 1>&2 redirects stdout to stderr.
|
|
There's a `black hole' called <TT
|
|
CLASS="LITERAL"
|
|
>/dev/null</TT
|
|
>: everything redirected to
|
|
it disappears; </P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> <EM
|
|
>wildcards</EM
|
|
>: '<TT
|
|
CLASS="LITERAL"
|
|
>*</TT
|
|
>' is almost the same. Usage: * matches all
|
|
files except the hidden ones; .* matches all hidden files; *.* matches
|
|
only those that have a '.' in the middle, followed by other characters;
|
|
p*r matches both `peter' and `piper'; *c* matches both `picked' and `peck'.
|
|
'<TT
|
|
CLASS="LITERAL"
|
|
>%</TT
|
|
>' becomes '<TT
|
|
CLASS="LITERAL"
|
|
>?</TT
|
|
>'. There is another wildcard: the
|
|
<TT
|
|
CLASS="LITERAL"
|
|
>[]</TT
|
|
>. Usage: <TT
|
|
CLASS="LITERAL"
|
|
>[abc]*</TT
|
|
> matches files starting with a, b, c;
|
|
<TT
|
|
CLASS="LITERAL"
|
|
>*[I-N,1,2,3]</TT
|
|
> matches files ending with I, J, K, L, M, N, 1, 2, 3; </P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> <TT
|
|
CLASS="LITERAL"
|
|
>mv</TT
|
|
> (<TT
|
|
CLASS="LITERAL"
|
|
>RENAME</TT
|
|
>) doesn't work for multiple files; that is,
|
|
<TT
|
|
CLASS="LITERAL"
|
|
>mv *.xxx *.yyy</TT
|
|
> won't work; </P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> use <TT
|
|
CLASS="LITERAL"
|
|
>cp -i</TT
|
|
> and <TT
|
|
CLASS="LITERAL"
|
|
>mv -i</TT
|
|
> to be warned when a file is going to
|
|
be overwritten. </P
|
|
></LI
|
|
></UL
|
|
> </P
|
|
></DIV
|
|
><DIV
|
|
CLASS="SECT2"
|
|
><HR><H2
|
|
CLASS="SECT2"
|
|
><A
|
|
NAME="PRINT-QUEUES"
|
|
></A
|
|
>8.4. Print Queues</H2
|
|
><P
|
|
>Your prints are queued, like under VMS. When you issue a print command, you
|
|
may specify a printer name. Example:</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>$ lpr file.txt # this goes to the standard printer
|
|
$ lpr -Plaser file.ps # this goes to the printer named 'laser'</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
><P
|
|
>To handle the print queues, you use the following commands:</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
> VMS Linux
|
|
------------------------------------------------------------------------------
|
|
|
|
$ PRINT file.ps $ lpr file.ps
|
|
$ PRINT/QUEUE=laser file.ps $ lpr -Plaser file.ps
|
|
$ SHOW QUEUE $ lpq
|
|
$ SHOW QUEUE/QUEUE=laser $ lpq -Plaser
|
|
$ STOP/QUEUE $ lprm <item> </PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
></DIV
|
|
></DIV
|
|
><DIV
|
|
CLASS="SECT1"
|
|
><HR><H1
|
|
CLASS="SECT1"
|
|
><A
|
|
NAME="CONFIGURING"
|
|
></A
|
|
>9. Configuring</H1
|
|
><P
|
|
>Your sysadm has already provided you with a number of configuration files
|
|
like <TT
|
|
CLASS="LITERAL"
|
|
>.xinitrc</TT
|
|
>, <TT
|
|
CLASS="LITERAL"
|
|
>.bash_profile</TT
|
|
>, <TT
|
|
CLASS="LITERAL"
|
|
>.inputrc</TT
|
|
>, and many others. The
|
|
ones you may want to edit are:</P
|
|
><P
|
|
> <P
|
|
></P
|
|
><UL
|
|
><LI
|
|
><P
|
|
> <TT
|
|
CLASS="LITERAL"
|
|
> .bash_profile</TT
|
|
> or <TT
|
|
CLASS="LITERAL"
|
|
>.profile</TT
|
|
>: read by the shell at login
|
|
time. It's like <TT
|
|
CLASS="LITERAL"
|
|
>LOGIN.COM</TT
|
|
>; </P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> <TT
|
|
CLASS="LITERAL"
|
|
> .bash_logout</TT
|
|
>: read by the shell at logout. It's like
|
|
<TT
|
|
CLASS="LITERAL"
|
|
>LOGOUT.COM</TT
|
|
>; </P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> <TT
|
|
CLASS="LITERAL"
|
|
> .bashrc</TT
|
|
>: read by non--login shells. </P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> <TT
|
|
CLASS="LITERAL"
|
|
> .inputrc</TT
|
|
>: this file customises the key bindings and the
|
|
behaviour of the shell. </P
|
|
></LI
|
|
></UL
|
|
> </P
|
|
><P
|
|
>To give you an example, I'll include my <TT
|
|
CLASS="LITERAL"
|
|
>.bash_profile</TT
|
|
> (abridged):</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="0"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="PROGRAMLISTING"
|
|
># $HOME/.bash_profile
|
|
|
|
# don't redefine the path if not necessary
|
|
echo $PATH | grep $LOGNAME > /dev/null
|
|
if [ $? != 0 ]
|
|
then
|
|
export PATH="$PATH:/home/$LOGNAME/bin" # add my dir to the PATH
|
|
fi
|
|
|
|
export PS1='LOGNAME:\w\$ '
|
|
export PS2='Continued...>'
|
|
|
|
# aliases
|
|
|
|
alias bin="cd ~/bin" ; alias cp="cp -i" ; alias d="dir"
|
|
alias del="delete" ; alias dir="/bin/ls $LS_OPTIONS --format=vertical"
|
|
alias ed="jed" ; alias mv='mv -i'
|
|
alias u="cd .." ; alias undel="undelete"
|
|
|
|
# A few useful functions
|
|
|
|
inst() # Install a .tar.gz archive in current directory.
|
|
{
|
|
gzip -dc $1 | tar xvf -
|
|
}
|
|
cz() # List the contents of a .zip archive.
|
|
{
|
|
unzip -l $*
|
|
}
|
|
ctgz() # List the contents of a .tar.gz archive.
|
|
{
|
|
for file in $* ; do
|
|
gzip -dc ${file} | tar tf -
|
|
done
|
|
}
|
|
tgz() # Create a .tgz archive a la zip.
|
|
{
|
|
name=$1 ; tar -cvf $1 ; shift
|
|
tar -rf ${name} $* ; gzip -S .tgz ${name}
|
|
}</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
><P
|
|
>And this is my <TT
|
|
CLASS="LITERAL"
|
|
>.inputrc</TT
|
|
>:</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="0"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="PROGRAMLISTING"
|
|
># $HOME/.inputrc
|
|
# Last modified: 16 January 1997.
|
|
#
|
|
# This file is read by bash and defines key bindings to be used by the shell;
|
|
# what follows fixes the keys END, HOME, and DELETE, plus accented letters.
|
|
# For more information, man readline.
|
|
|
|
"\e[1~": beginning-of-line
|
|
"\e[3~": delete-char
|
|
"\e[4~": end-of-line
|
|
|
|
set bell-style visible
|
|
set meta-flag On
|
|
set convert-meta Off
|
|
set output-meta On
|
|
set horizontal-scroll-mode On
|
|
set show-all-if-ambiguous On
|
|
|
|
# (F1 .. F5) are "\e[[A" ... "\e[[E"
|
|
|
|
"\e[[A": "info "</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
></DIV
|
|
><DIV
|
|
CLASS="SECT1"
|
|
><HR><H1
|
|
CLASS="SECT1"
|
|
><A
|
|
NAME="USEFUL-PROGRAMS"
|
|
></A
|
|
>10. Useful Programs</H1
|
|
><DIV
|
|
CLASS="SECT2"
|
|
><H2
|
|
CLASS="SECT2"
|
|
><A
|
|
NAME="AEN617"
|
|
></A
|
|
>10.1. Browsing Files: <TT
|
|
CLASS="LITERAL"
|
|
>less</TT
|
|
></H2
|
|
><P
|
|
>You'll use this file browser every day, so I'll give you a couple of tips to
|
|
use it at best. First of all, ask your sysadm to configure <TT
|
|
CLASS="LITERAL"
|
|
>less</TT
|
|
> so as
|
|
it can display not only plain text files, but also compressed files,
|
|
archives, and so on.</P
|
|
><P
|
|
>Like recent versions of <TT
|
|
CLASS="LITERAL"
|
|
>TYPE</TT
|
|
>, <TT
|
|
CLASS="LITERAL"
|
|
>less</TT
|
|
> lets you browse files
|
|
in both directions. It also accepts several commands that are issued
|
|
pressing a key. The most useful are:</P
|
|
><P
|
|
> <P
|
|
></P
|
|
><UL
|
|
><LI
|
|
><P
|
|
> first of all, press <TT
|
|
CLASS="LITERAL"
|
|
>q</TT
|
|
> to leave the browser; </P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> <TT
|
|
CLASS="LITERAL"
|
|
>h</TT
|
|
> gives you extensive help; </P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> <TT
|
|
CLASS="LITERAL"
|
|
>g</TT
|
|
> to go to beginning of file, <TT
|
|
CLASS="LITERAL"
|
|
>G</TT
|
|
> to the end, number+<TT
|
|
CLASS="LITERAL"
|
|
>g</TT
|
|
>
|
|
to go to line `number' (e.g. <TT
|
|
CLASS="LITERAL"
|
|
>125g</TT
|
|
>), number+<TT
|
|
CLASS="LITERAL"
|
|
>%</TT
|
|
> to move to that
|
|
percentage of the file; </P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> <TT
|
|
CLASS="LITERAL"
|
|
>/pattern</TT
|
|
> searches forwards for `pattern'; <TT
|
|
CLASS="LITERAL"
|
|
>n</TT
|
|
> searches
|
|
forwards for the next match; <TT
|
|
CLASS="LITERAL"
|
|
>?pattern</TT
|
|
> and <TT
|
|
CLASS="LITERAL"
|
|
>N</TT
|
|
> search backwards; </P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> <TT
|
|
CLASS="LITERAL"
|
|
>m</TT
|
|
>+letter marks current position (e.g. <TT
|
|
CLASS="LITERAL"
|
|
>ma</TT
|
|
>); <TT
|
|
CLASS="LITERAL"
|
|
>'</TT
|
|
>+letter go
|
|
to the marked position. </P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> <TT
|
|
CLASS="LITERAL"
|
|
>:e</TT
|
|
> examines a new file; </P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> <TT
|
|
CLASS="LITERAL"
|
|
>!command</TT
|
|
> executes the shell command. </P
|
|
></LI
|
|
></UL
|
|
> </P
|
|
></DIV
|
|
><DIV
|
|
CLASS="SECT2"
|
|
><HR><H2
|
|
CLASS="SECT2"
|
|
><A
|
|
NAME="NUMBERED-BACKUPS-UNDER-LINUX"
|
|
></A
|
|
>10.2. Numbered Backups Under Linux</H2
|
|
><P
|
|
>Alas, Linux doesn't still support file version numbers, but you overcome
|
|
this limitation in two ways. The first is to use RCS, the Revision Control
|
|
System, which allows you to keep previous versions of a file. RCS is
|
|
covered in ``The RCS MINI-HOWTO'' (<A
|
|
HREF="http://sunsite.unc.edu/mdw/HOWTO/mini/RCS.html"
|
|
TARGET="_top"
|
|
>�</A
|
|
>).</P
|
|
><P
|
|
>The second way is to use an editor that knows how to deal with numbered
|
|
backups; <TT
|
|
CLASS="LITERAL"
|
|
>emacs</TT
|
|
> and <TT
|
|
CLASS="LITERAL"
|
|
>jed</TT
|
|
> are OK. In <TT
|
|
CLASS="LITERAL"
|
|
>emacs</TT
|
|
>, add
|
|
these lines in your <TT
|
|
CLASS="LITERAL"
|
|
>.emacs</TT
|
|
>:</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>(setq version-control t)
|
|
(setq kept-new-versions 15) ;;; or any other value
|
|
(setq kept-old-versions 15)
|
|
(setq backup-by-copying-when-linked t)
|
|
(setq backup-by-copying-when-mismatch t)</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
><P
|
|
>In <TT
|
|
CLASS="LITERAL"
|
|
>jed</TT
|
|
>, make sure you have version 0.98.7 or newer; the patch for
|
|
numbered backups is available on <TT
|
|
CLASS="LITERAL"
|
|
> <A
|
|
HREF="http://ibogeo.df.unibo.it/guido/slang/backups.sl"
|
|
TARGET="_top"
|
|
>�</A
|
|
> </TT
|
|
>.</P
|
|
></DIV
|
|
><DIV
|
|
CLASS="SECT2"
|
|
><HR><H2
|
|
CLASS="SECT2"
|
|
><A
|
|
NAME="AEN672"
|
|
></A
|
|
>10.3. Archiving: tar & gzip</H2
|
|
><P
|
|
>Under UNIX there are some widely used applications to archive and
|
|
compress files. <TT
|
|
CLASS="LITERAL"
|
|
>tar</TT
|
|
> is used to make archives, that is collections of
|
|
files. To make a new archive:</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>$ tar -cvf <archive_name.tar> <file> [file...]</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
><P
|
|
>To extract files from an archive:</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>$ tar -xpvf <archive_name.tar> [file...]</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
><P
|
|
>To list the contents of an archive:</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>$ tar -tf <archive_name.tar> | less</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
><P
|
|
>Files can be compressed to save disk space using <TT
|
|
CLASS="LITERAL"
|
|
>compress</TT
|
|
>, which is
|
|
obsolete and shouldn't be used any more, or <TT
|
|
CLASS="LITERAL"
|
|
>gzip</TT
|
|
>:</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>$ compress <file>
|
|
$ gzip <file></PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
><P
|
|
>that creates a compressed file with extension .Z (<TT
|
|
CLASS="LITERAL"
|
|
>compress</TT
|
|
>) or .gz
|
|
(<TT
|
|
CLASS="LITERAL"
|
|
>gzip</TT
|
|
>). These programs don't make archives, but compress files
|
|
individually. To decompress, use:</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>$ compress -d <file.Z>
|
|
$ gzip -d <file.gz></PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
><P
|
|
>RMP.</P
|
|
><P
|
|
>The <TT
|
|
CLASS="LITERAL"
|
|
>unarj</TT
|
|
>, <TT
|
|
CLASS="LITERAL"
|
|
>zip</TT
|
|
> and <TT
|
|
CLASS="LITERAL"
|
|
>unzip</TT
|
|
> utilities are also available. Files
|
|
with extension <TT
|
|
CLASS="LITERAL"
|
|
>.tar.gz</TT
|
|
> or <TT
|
|
CLASS="LITERAL"
|
|
>.tgz</TT
|
|
> (archived with <TT
|
|
CLASS="LITERAL"
|
|
>tar</TT
|
|
>, then
|
|
compressed with <TT
|
|
CLASS="LITERAL"
|
|
>gzip</TT
|
|
>) are very common in the UNIX world. Here's how to
|
|
list the contents of a <TT
|
|
CLASS="LITERAL"
|
|
>.tar.gz</TT
|
|
> archive:</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>$ tar -ztf <file.tar.gz> | less</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
><P
|
|
>To extract the files from a <TT
|
|
CLASS="LITERAL"
|
|
>.tar.gz</TT
|
|
> archive:</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>$ tar -zxf <file.tar.gz></PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
></DIV
|
|
></DIV
|
|
><DIV
|
|
CLASS="SECT1"
|
|
><HR><H1
|
|
CLASS="SECT1"
|
|
><A
|
|
NAME="EXAMPLES"
|
|
></A
|
|
>11. Real Life Examples</H1
|
|
><P
|
|
>UNIX' core idea is that there are many simple commands that can linked
|
|
together via piping and redirection to accomplish even really complex tasks.
|
|
Have a look at the following examples. I'll only explain the most complex
|
|
ones; for the others, please study the above sections and the man pages.</P
|
|
><P
|
|
><EM
|
|
>Problem</EM
|
|
>: <TT
|
|
CLASS="LITERAL"
|
|
>ls</TT
|
|
> is too quick and the file names fly away.</P
|
|
><P
|
|
><EM
|
|
>Solution</EM
|
|
>:</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>$ ls | less</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
><P
|
|
><EM
|
|
>Problem</EM
|
|
>: I have a file containing a list of words. I want to sort it
|
|
in reverse order and print it.</P
|
|
><P
|
|
><EM
|
|
>Solution</EM
|
|
>:</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>$ cat myfile.txt | sort -r | lpr</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
><P
|
|
><EM
|
|
>Problem</EM
|
|
>: my data file has some repeated lines! How do I get rid of them?</P
|
|
><P
|
|
><EM
|
|
>Solution</EM
|
|
>:</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>$ sort datafile.dat | uniq > newfile.dat</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
><P
|
|
><EM
|
|
>Problem</EM
|
|
>: I have a file called 'mypaper.txt' or 'mypaper.tex' or some
|
|
such somewhere, but I don't remember where I put it. How do I find it?</P
|
|
><P
|
|
><EM
|
|
>Solution</EM
|
|
>:</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>$ find ~ -name "mypaper*" </PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
><P
|
|
>Explanation: <TT
|
|
CLASS="LITERAL"
|
|
>find</TT
|
|
> is a very useful command that lists all the files
|
|
in a directory tree (starting from <TT
|
|
CLASS="LITERAL"
|
|
>˜</TT
|
|
> in this case). Its output
|
|
can be filtered to meet several criteria, such as <TT
|
|
CLASS="LITERAL"
|
|
>-name</TT
|
|
>.</P
|
|
><P
|
|
><EM
|
|
>Problem</EM
|
|
>: I have a text file containing the word 'entropy' in this
|
|
directory, is there anything like <TT
|
|
CLASS="LITERAL"
|
|
>SEARCH</TT
|
|
>?</P
|
|
><P
|
|
><EM
|
|
>Solution</EM
|
|
>: yes, try</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>$ grep -l 'entropy' *</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
><P
|
|
><EM
|
|
>Problem</EM
|
|
>: somewhere I have text files containing the word 'entropy', I'd
|
|
like to know which and where they are. Under VMS I'd use <TT
|
|
CLASS="LITERAL"
|
|
>search entropy
|
|
[...]*.*;*</TT
|
|
>, but <TT
|
|
CLASS="LITERAL"
|
|
>grep</TT
|
|
> can't recurse subdirectories. Now what?</P
|
|
><P
|
|
><EM
|
|
>Solution</EM
|
|
>: </P
|
|
><P
|
|
> <TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>$ find . -exec grep -l "entropy" {} \; 2> /dev/null</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
><P
|
|
>Explanation: <TT
|
|
CLASS="LITERAL"
|
|
>find .</TT
|
|
> outputs all the file names starting from the
|
|
current directory, <TT
|
|
CLASS="LITERAL"
|
|
>-exec grep -l "entropy"</TT
|
|
> is an action to be
|
|
performed on each file (represented by <TT
|
|
CLASS="LITERAL"
|
|
>{}</TT
|
|
>), <TT
|
|
CLASS="LITERAL"
|
|
>\</TT
|
|
>
|
|
terminates the command. If you think this syntax is awful, you're right.</P
|
|
><P
|
|
>In alternative, write the following script:</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="0"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="PROGRAMLISTING"
|
|
>#!/bin/sh
|
|
# rgrep: recursive grep
|
|
if [ $# != 3 ]
|
|
then
|
|
echo "Usage: rgrep --switches 'pattern' 'directory'"
|
|
exit 1
|
|
fi
|
|
find $3 -name "*" -exec grep $1 $2 {} \; 2> /dev/null</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
><P
|
|
>Explanation: <TT
|
|
CLASS="LITERAL"
|
|
>grep</TT
|
|
> works like <TT
|
|
CLASS="LITERAL"
|
|
>search</TT
|
|
>, and combining it with
|
|
<TT
|
|
CLASS="LITERAL"
|
|
>find</TT
|
|
> we get the best of both worlds.</P
|
|
><P
|
|
><EM
|
|
>Problem</EM
|
|
>: I have a data file that has two header lines, then every
|
|
line has 'n' data, not necessarily equally spaced. I want the 2nd and
|
|
5th data value of each line. Shall I write a Fortran program...?</P
|
|
><P
|
|
><EM
|
|
>Solution</EM
|
|
>: nope. This is quicker:</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>$ awk 'NL > 2 {print $2, "\t", $5}' datafile.dat > newfile.dat</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
><P
|
|
>Explanation: the command <TT
|
|
CLASS="LITERAL"
|
|
>awk</TT
|
|
> is actually a programming language:
|
|
for each line starting from the third in <TT
|
|
CLASS="LITERAL"
|
|
>datafile.dat</TT
|
|
>, print out
|
|
the second and fifth field, separated by a tab. Learn some <TT
|
|
CLASS="LITERAL"
|
|
>awk</TT
|
|
>---it
|
|
saves a lot of time.</P
|
|
><P
|
|
><EM
|
|
>Problem</EM
|
|
>: I've downloaded an FTP site's <TT
|
|
CLASS="LITERAL"
|
|
>ls-lR.gz</TT
|
|
> to check its
|
|
contents. For each subdirectory, it contains a line that reads "total xxxx",
|
|
where xxxx is size in kbytes of the dir contents. I'd like to get the grand
|
|
total of all these xxxx values.</P
|
|
><P
|
|
><EM
|
|
>Solution</EM
|
|
>:</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>$ zcat ls-lR.gz | awk ' $1 == "total" { i += $2 } END {print i}'</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
><P
|
|
>Explanation: <TT
|
|
CLASS="LITERAL"
|
|
>zcat</TT
|
|
> outputs the contents of the <TT
|
|
CLASS="LITERAL"
|
|
>.gz</TT
|
|
> file and pipes
|
|
to <TT
|
|
CLASS="LITERAL"
|
|
>awk</TT
|
|
>, whose man page you're kindly requested to read ;-)</P
|
|
><P
|
|
><EM
|
|
>Problem</EM
|
|
>: I've written a Fortran program, <TT
|
|
CLASS="LITERAL"
|
|
>myprog</TT
|
|
>, to calculate a
|
|
parameter from a data file. I'd like to run it on hundreds of data files
|
|
and have a list of the results, but it's a nuisance to ask each time for
|
|
the file name. Under VMS I'd write a lengthy command file, and under Linux?</P
|
|
><P
|
|
><EM
|
|
>Solution</EM
|
|
>: a very short script. Make your program look for the data
|
|
file '<TT
|
|
CLASS="LITERAL"
|
|
>mydata.dat</TT
|
|
>' and print the result on the screen (stdout), then
|
|
write the following script:</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="0"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="PROGRAMLISTING"
|
|
>#!/bin/sh
|
|
# myprog.sh: run the same command on many different files
|
|
# usage: myprog.sh *.dat
|
|
for file in $* # for all parameters (e.g. *.dat)
|
|
do
|
|
# append the file name to result.dat
|
|
echo -n "${file}: " >> results.dat
|
|
# copy current argument to mydata.dat, run myprog
|
|
# and append the output to results.dat
|
|
cp ${file} mydata.dat ; myprog >> results.dat
|
|
done</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
><P
|
|
><EM
|
|
>Problem</EM
|
|
>: I want to replace `geology' with `geophysics' in all my
|
|
text files. Shall I edit them all manually?</P
|
|
><P
|
|
><EM
|
|
>Solution</EM
|
|
>: nope. Write this shell script:</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="0"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="PROGRAMLISTING"
|
|
>#!/bin/sh
|
|
# replace $1 with $2 in $*
|
|
# usage: replace "old-pattern" "new-pattern" file [file...]
|
|
OLD=$1 # first parameter of the script
|
|
NEW=$2 # second parameter
|
|
shift ; shift # discard the first 2 parameters: the next are the file names
|
|
for file in $* # for all files given as parameters
|
|
do
|
|
# replace every occurrence of OLD with NEW, save on a temporary file
|
|
sed "s/$OLD/$NEW/g" ${file} > ${file}.new
|
|
# rename the temporary file as the original file
|
|
/bin/mv ${file}.new ${file}
|
|
done</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
><P
|
|
><EM
|
|
>Problem</EM
|
|
>: I have some data files, I don't know their length and have to
|
|
remove their last but one and last but two lines. Er... manually?</P
|
|
><P
|
|
><EM
|
|
>Solution</EM
|
|
>: no, of course. Write this script:</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="0"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="PROGRAMLISTING"
|
|
>#!/bin/sh
|
|
# prune.sh: removes n-1th and n-2th lines from files
|
|
# usage: prune.sh file [file...]
|
|
for file in $* # for every parameter
|
|
do
|
|
LINES=`wc -l $file | awk '{print $1}'` # number of lines in file
|
|
LINES=`expr $LINES - 3` # LINES = LINES - 3
|
|
head -n $LINES $file > $file.new # output first LINES lines
|
|
tail -n 1 $file >> $file.new # append last line
|
|
done</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
><P
|
|
>I hope these examples whetted your appetite...</P
|
|
></DIV
|
|
><DIV
|
|
CLASS="SECT1"
|
|
><HR><H1
|
|
CLASS="SECT1"
|
|
><A
|
|
NAME="AEN811"
|
|
></A
|
|
>12. Tips You Can't Do Without</H1
|
|
><P
|
|
> <P
|
|
></P
|
|
><UL
|
|
><LI
|
|
><P
|
|
> <EM
|
|
>Command completion</EM
|
|
>: pressing <TAB> when issuing a command
|
|
will complete the command line for you. Example: you have to type
|
|
<TT
|
|
CLASS="LITERAL"
|
|
>less this_is_a_long_name</TT
|
|
>; typing in <TT
|
|
CLASS="LITERAL"
|
|
>less thi<TAB></TT
|
|
>
|
|
will suffice. (If you have other files that start with the same
|
|
characters, supply enough characters to resolve any ambiguity.) </P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> <EM
|
|
>Back-scrolling</EM
|
|
>: pressing SHIFT--PAG UP (the grey key) allows
|
|
you to backscroll a few pages, depending on your PC's video memory. </P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> <EM
|
|
>Resetting the screen</EM
|
|
>: if you happen to <TT
|
|
CLASS="LITERAL"
|
|
>more</TT
|
|
> or <TT
|
|
CLASS="LITERAL"
|
|
>cat</TT
|
|
>
|
|
a binary file, your screen may end up full of garbage. To fix things,
|
|
blind type <TT
|
|
CLASS="LITERAL"
|
|
>reset</TT
|
|
> or this sequence of characters:
|
|
<TT
|
|
CLASS="LITERAL"
|
|
>echo CTRL-V ESC c RETURN</TT
|
|
>. </P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> <EM
|
|
>Pasting text</EM
|
|
>: in console, see below; in X, click and drag to
|
|
select the text in an <TT
|
|
CLASS="LITERAL"
|
|
>xterm</TT
|
|
> window, then click the middle button
|
|
(or the two buttons together if you have a two-button mouse) to paste. </P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> <EM
|
|
>Using the mouse</EM
|
|
>: ask your sysadm to install <TT
|
|
CLASS="LITERAL"
|
|
>gpm</TT
|
|
>, a mouse
|
|
driver for the console. Click and drag to select text, then right click
|
|
to paste the selected text. It works across different VCs. </P
|
|
></LI
|
|
></UL
|
|
> </P
|
|
></DIV
|
|
><DIV
|
|
CLASS="SECT1"
|
|
><HR><H1
|
|
CLASS="SECT1"
|
|
><A
|
|
NAME="AEN838"
|
|
></A
|
|
>13. Reading VMS tapes from Linux</H1
|
|
><P
|
|
>(This section was written by Mike Miller)</P
|
|
><DIV
|
|
CLASS="SECT2"
|
|
><HR><H2
|
|
CLASS="SECT2"
|
|
><A
|
|
NAME="AEN841"
|
|
></A
|
|
>13.1. Introduction</H2
|
|
><P
|
|
>From time to time you may want to read tapes made on a VMS machine (or tapes
|
|
that are made to be readable by VMS and *nix systems). In general, this is
|
|
quite easy for DECFILES11A tapes.</P
|
|
><P
|
|
>Although you may be reading this as part of a Linux mini-HOWTO, I believe
|
|
that the information here is applicable to any *nix system - I've done this
|
|
on Linux, HP, Sun and DEC *nix systems. The main platform dependences that I
|
|
know are device names, which can differ on different systems, and the
|
|
options to mt for specifying the device name (for example, mt -f on Linux
|
|
and mt -t on HPUX 9).</P
|
|
><P
|
|
>Caveat - I've only tried this with Exabyte 8mm SCSI tape drives. If you've
|
|
read other formats (still got those 9-tracks lying around?) let me know and
|
|
I'll add a note here.</P
|
|
></DIV
|
|
><DIV
|
|
CLASS="SECT2"
|
|
><HR><H2
|
|
CLASS="SECT2"
|
|
><A
|
|
NAME="AEN846"
|
|
></A
|
|
>13.2. The Basics</H2
|
|
><P
|
|
>When reading a tape that has been made with the VMS ``copy'' command (or has
|
|
at least been made to look like it was made with copy) all you need to know
|
|
is there will be three files on the tape for each actual data file - a
|
|
header, the data, and a trailer. The header and trailer are interesting in
|
|
that they contain info on the file as it existed under VMS. The data is,
|
|
well, the data. Each of these files can be extracted from the tape with the
|
|
dd command. The tape can be positioned by skipping around with the mt
|
|
command.</P
|
|
><P
|
|
>Example: I've got VMS tape with a series of files on it. The first two were
|
|
originally named ce66-2.evt and ce66-3.evt on a VMS system. The tape label
|
|
is c66a2.</P
|
|
><P
|
|
>If I execute these commands:</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>> dd if=$TAPE bs=16k of=header1
|
|
> dd if=$TAPE bs=16k of=data1
|
|
> dd if=$TAPE bs=16k of=trailer1
|
|
> dd if=$TAPE bs=16k of=header2
|
|
> dd if=$TAPE bs=16k of=data2
|
|
> dd if=$TAPE bs=16k of=trailer2</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
><P
|
|
>I'm left with six files: header1, data1, trailer1, header2, data2 and
|
|
trailer2. The syntax here is if="input file", bs="block size" and
|
|
of="output file". TAPE is expected to be a variable containing the device
|
|
name of your tape drive - for example, /dev/nts0 if you are using the first
|
|
SCSI tape on Linux.</P
|
|
><P
|
|
>If you wanted to read the second file, but not the first, you didn't care
|
|
about the header, and you wanted to use the original file name, do this:</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>> mt -f $TAPE fsf 4
|
|
> dd if=$TAPE bs=16k of=ce66-2.evt
|
|
> mt -f $TAPE fsf 1</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
><P
|
|
>Note the 4 - skip three files for the first file on the tape and one for the
|
|
next header. The second mt skips the second file's trailer and positions
|
|
the tape at the beginning of the next file - the third VMS header. You can
|
|
also use mt to skip backwards (bsf), rewind (rewind) and rewind and unload
|
|
the tape (offline, rewoffl).</P
|
|
></DIV
|
|
><DIV
|
|
CLASS="SECT2"
|
|
><HR><H2
|
|
CLASS="SECT2"
|
|
><A
|
|
NAME="AEN858"
|
|
></A
|
|
>13.3. Some details</H2
|
|
><P
|
|
>The header and trailer files contain uppercase ASCII data used by VMS to
|
|
store file information such as block size. They also contain the file name,
|
|
which can be handy if you want to build scripts that automate read files or
|
|
search for a particular file. The first header on a tape volume is slightly
|
|
different than subsequent headers.</P
|
|
><P
|
|
>For a file that is the first file on the tape, as in header1 of the above
|
|
example, the first four characters will be "VOL1" followed by the volume
|
|
name. In the example, header1 starts with "VOL1C66A2". This is followed by
|
|
a series of spaces terminated with a numeral. After that is the string
|
|
"HDR1" which indicates that this is a file header. The characters
|
|
immediately following the HDR1 string are the VMS file name. In in the
|
|
example, this is "HDR1CE66-2.EVT". The next field is the volume name again.</P
|
|
><P
|
|
>For files that are not the first file on the tape, the initial VOL1 field is
|
|
not present. Other than that the header has the same structure as for the
|
|
initial file. Another useful field is the 7th field, which will end with
|
|
"DECFILES11A". This must be present on tapes that conform to the DEC
|
|
Files11A standard.</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
> field initial header subsequent headers
|
|
===== ============= ==================
|
|
1 VOL1 + volume name HDR1 + file name
|
|
2 3HDR1 + file name volume name
|
|
3 volume name
|
|
|
|
6 ...DECFILES11A
|
|
7 ...DECFILES11A</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
> </P
|
|
><P
|
|
>For full details on the header and trailer format, see the DEC FILES11A
|
|
documentation (on the orange/grey wall - ask your local VMS folks :-).</P
|
|
></DIV
|
|
><DIV
|
|
CLASS="SECT2"
|
|
><HR><H2
|
|
CLASS="SECT2"
|
|
><A
|
|
NAME="AEN866"
|
|
></A
|
|
>13.4. Comment on Block Size</H2
|
|
><P
|
|
>In the example, I used a block size of 16k. On a *nix system, there is no
|
|
block size associated with a file on disk while, under VMS, each file has a
|
|
specific block size. That means that block size doesn't matter too much on
|
|
the Linux end... unless it makes it hard to read the tape. If you have
|
|
difficulty figuring out the block size and reading a tape, you can try
|
|
setting the hardware block size on your tape drive using `mt -f $TAPE setblk
|
|
0'. The exact form of the setblk option (and its availability) may depend
|
|
on the version of mt, the tape drive hardware interface and on your
|
|
particular flavor of *nix.</P
|
|
><P
|
|
>(Thanks to Wojtek Skulski (<A
|
|
HREF="skulski@nsrlc6.nsrl.rochester.edu"
|
|
TARGET="_top"
|
|
>�</A
|
|
>)
|
|
for pointing out setblk.)</P
|
|
></DIV
|
|
></DIV
|
|
><DIV
|
|
CLASS="SECT1"
|
|
><HR><H1
|
|
CLASS="SECT1"
|
|
><A
|
|
NAME="AEN871"
|
|
></A
|
|
>14. The End</H1
|
|
><DIV
|
|
CLASS="SECT2"
|
|
><H2
|
|
CLASS="SECT2"
|
|
><A
|
|
NAME="AEN873"
|
|
></A
|
|
>14.1. Copyright</H2
|
|
><P
|
|
>Unless otherwise stated, Linux HOWTO documents are copyrighted by their
|
|
respective authors. Linux HOWTO documents may be reproduced and distributed
|
|
in whole or in part, in any medium physical or electronic, as long as this
|
|
copyright notice is retained on all copies. Commercial redistribution is
|
|
allowed and encouraged; however, the author would like to be notified of any
|
|
such distributions.</P
|
|
><P
|
|
>All translations, derivative works, or aggregate works incorporating any
|
|
Linux HOWTO documents must be covered under this copyright notice. That is,
|
|
you may not produce a derivative work from a HOWTO and impose additional
|
|
restrictions on its distribution. Exceptions to these rules may be granted
|
|
under certain conditions; please contact the Linux HOWTO coordinator at the
|
|
address given below.</P
|
|
><P
|
|
>In short, we wish to promote dissemination of this information through as
|
|
many channels as possible. However, we do wish to retain copyright on the
|
|
HOWTO documents, and would like to be notified of any plans to redistribute
|
|
the HOWTOs.</P
|
|
><P
|
|
>If you have questions, please contact Tim Bynum, the Linux HOWTO
|
|
coordinator, at <A
|
|
HREF="linux-howto@sunsite.unc.edu"
|
|
TARGET="_top"
|
|
>�</A
|
|
> via email.</P
|
|
></DIV
|
|
><DIV
|
|
CLASS="SECT2"
|
|
><HR><H2
|
|
CLASS="SECT2"
|
|
><A
|
|
NAME="AEN880"
|
|
></A
|
|
>14.2. Disclaimer</H2
|
|
><P
|
|
>This work was written following the experience we had at the Settore di
|
|
Geofisica of the Universita' di Bologna (Italy), where a VAX 4000 has been
|
|
superseded and replaced by Linux-based Pentium PCs. Most of my colleagues
|
|
are VMS users, and some of them have switched to Linux.</P
|
|
><P
|
|
>``From VMS to Linux HOWTO'' was written by Guido Gonzato, <A
|
|
HREF="guido ``at'' ibogeo.df.unibo.it"
|
|
TARGET="_top"
|
|
>�</A
|
|
>, and Mike Miller,
|
|
<A
|
|
HREF="miller5@uiuc.edu"
|
|
TARGET="_top"
|
|
>�</A
|
|
> who contributed the section on reading VMS tapes.
|
|
Many thanks to my colleagues and friends who helped me define the needs and
|
|
habits of the average VMS user, especially to Dr. Warner Marzocchi.</P
|
|
><P
|
|
>Please help me improve this HOWTO. I'm not a VMS expert and never will be,
|
|
so your suggestions and bug reports are more than welcome.</P
|
|
><P
|
|
>Enjoy,</P
|
|
><P
|
|
>Guido <TT
|
|
CLASS="LITERAL"
|
|
>=8-)</TT
|
|
></P
|
|
></DIV
|
|
></DIV
|
|
></DIV
|
|
></BODY
|
|
></HTML
|
|
> |