(Message inbox:1483)
Return-Path: Weitzman.IPCPubs@MIT-MULTICS.ARPA
Received: by JASON (5.45/4.7)
	id AA16791; Fri, 23 May 86 15:22:37 EDT
Received: by ATHENA (5.45/4.7)
	id AA03073; Fri, 23 May 86 15:22:04 EDT
Date:  Fri, 23 May 86 14:52 EDT
From: Weitzman@MIT-MULTICS.ARPA
Subject:  files on athena
To: lbm@ATHENA.MIT.EDU
Message-Id:  <860523185217.993996@MIT-MULTICS.ARPA>

@device(imprint10)
@make(report)
@definefont(Userfont, 1=<Typecase ComputerModernBold10R36>,
                      2=<Typecase ComputerModernBold10R20>,
                      3=<Typecase ComputerModernBold10R18>,
                      4=<typecase computermodernbold10R14>,
                      5=<typecase computermodernbold10R12>,
                      6=<typecase computermodernbold10R10>)
@modify(hd1, font userfont, facecode 2, flushright, below 1 inch)
@modify(hd2, font userfont, facecode 4, leftmargin -2)
@modify(copyrightnotice, flushright, fixed -1 inch)
@Style(Font computermodernroman11)
@Style(spacing 1,indent 0)
@Style(leftmargin 1.0inch)
@Style(Linewidth 6.5inches)
@pageheading(odd, left="@b(Files Unix)", center="", 
            right="")
@pageheading(even, left="", 
        center="", right="@b(Files Unix)")
@pagefooting(left="@b(MIT Project Athena)", center="@value(page)", 
      right="@b(Files)")

@chapter(Files)
A @b(file) is a body of information with a name.  Most commands and functions
act on files.  Commands you enter are really names of files.  There are two
main types of files, simple files and @b(directories).  We will begin by
discussing simple files and leave directories until the next section.

@section(File Names)

File names can be from one to 256 characters long.  You may use any character
on the keyboard except a / (slash) in a file name, but it is wisest to stick
to a-z, A-Z, 0-9, the .  (period or "dot"), and _ (underscore) characters.
Use of other characters, may be difficult.  As noted earlier, case matters in
file names; @i(myfile) is a different file from @i(Myfile).


@b(File Naming Conventions)

Often Unix file names contain @b(extensions).  For example:
@i(program.h, paper.mss).  The ".xxx" is the extension.  People do
this to remind themselves of file types, (A @i(.h) file is a
C language "include" file), or because some Unix programs have proper
extensions; @i(.c) for C, @i(.f) for Fortran, and @i(.p) for Pascal.

=== HOW ABOUT INSERTING A SMALL CHART HERE OF COMMON FILENAME EXTS. === 

Some file names @i(start) with a .  (dot), e.g., @i(.cshrc) or @i(.login).
These files do not show up when you list your files unless you 
ask for them.  === SEE LS COMMAND, REF.  ==

@b(Wildcards:  * and ?)

@b(wildcard characters) provide a shorthand notation for referring to
many files at once.

Here are the two most useful wildcard characters:
@begin(description)
*@\Matches all files except those whose names begin with @b(.) (dot).
   It can also match characters within a filename.  For example,
   @i(*.f) means "all the files with a .f extension."  @i(h.f) and
   @i(verylongfilename.f) would both match.  @i(a*) means "all the files
   that begin with a"  File names @i(a) and @i(anothernameforyou) would
   both match.

?@\Matches single characters.  @i(?.f) means all one character file
   names with extensions of @i(.f).  @i(a.f) would match.  @i(ab.f) would not.
@end(description)
The section on "Directories" has examples of wildcard characters in use.



@section(Create a File)

@subsection(Creating a File with Cat)

@b(Cat) is a "quick and dirty" method of creating a file.  You might see it
referred to as "redirecting a file".  It works as follows.

=== IS IT CLEAR THAT THE TEXT FROM THE FOLLOWING EXAMPLE IS PERTINENT TO THE
SUBSECTION?  SHOULE I SET OFF EXPLANATION SOMEHOW?? ===

@example[
host%  cat >easyfile
Unix just moves the cursor down to the
next line.  You begin to type.  End each line
with a RETURN.  You can fix typing mistakes
with the DELETE key in the line you are currently
typing.  You can erase the whole line you are
typing currently with CTRL-U.
There is no way to fix previous lines.
When you are done, finish the last line with
a RETURN and then at the beginning of the next
line enter just CTRL-D.  It echoes as ^D.
^D
host%
]
Once a line is entered with cat, there is no way to change it short of
deleting it and re-entering the whole thing or changing the file later with a
different kind of editor.
@b(Don't forget to assign a @p(>filename) in your cat command line.)
Without a filename, @b(cat) will echo your input without creating a
new file.  @b(>filename) tells @b(cat) to
save the text as a file.

@section(Redirecting Output)

=== INSERT SUSAN'S MORE ON PIPING AND I/O MATERIAL ===

You can take the output of any Unix command and put it into a
file.  For example, the command that shows you what electronic
mail messages you have is @p(scan):
@example[
host%  scan
102   2/10   cec (Cecilia d'O  Re: IPS educational and consulting 
104   2/10   jg (Jim Gettys)   UUCP outgoing mail.  <<Now works p
105   2/10   cec (Cecilia d'O  DEC Orientation Meeting Agenda
109   2/12   gary (Gary McDon  bldg 1 printers  <<The LN01 and th
]
When you enter this command, the output from the command is
displayed on the screen.  If you want to save what you
see on the screen as a file,  @b(redirect) the
output of the command into a file:
@example[
host%  scan >mymail
host%  ls
Mail  easyfile  mymail  welcome
]
The ">filename" at the end of the command line is the redirection
mechanism.  Be sure your arrow is pointing the right way.  It is
all right to have a blank space between the > and the filename you
have selected.  This "quick
and dirty" mechanism redirects the
output of the @v(cat) command to a file, in this case one named @i(mymail).


@section(Common File Commands)

=== REMOTE FILE COMMANDS === CHART?

@b(List Your Files:  ls)

To list the files in a directory use the @b(ls) command.

If you are a new Athena user and you type @i(ls), this is roughly what
you will see:
@example[
host%  ls
Mail    welcome
]
=== ARE THESE THE DEFAULT FILES INCLUDED IN A NEW ACCOUNT?  INDICATE? ===
@i(ls) by itself lists file names, alphabetically (A-Z before
a-z) in as many columns as will fit across the screen.

The @b(ls) command has many options.  To see all the options, type
"man ls" while logged in at a terminal.  Here are the most important
options.

@b(-a for All)

To get a list of all of the files in a directory, including those
whose names begin with a @b(.) (dot) character, use the @p(-a) option
(for "all").  A new user doing this would see something like:
@example[
host%  ls -a
.        .emacs_keys       .logout       .tiprc
..       .emacs_vars       .mailrc       Mail
.cshrc   .login            .mh_profile   welcome
]
Remember, @i(ls) doesn't show the files whose names begin
with ., and @i(ls -a) does.

@b(-l for Long)

To get a "long" listing of your files that shows much more information about
them, use @p(ls -l).
@example[
host%  ls -l
drwx--x--x  1 you         2 Nov  3  1983 Mail
-rw-------  1 you         0 Nov  3  1983 mbox
-rw-r--r--  1 you       404 Nov 27  1983 welcome
]

The first set of information on the line is the file's @b(mode), (who has
access).  The r's and x's that follow show who has permission to read, write,
delete, and execute the file.  This is explained in more detail in the section
on "File Protection" below.  A "d" in the first column means that the file is
a directory.

The second column shows the number of "links" the file has.  === EITHER GIVE
REFERENCE FOR LINKS OR INSERT EXPLANATION === For directories, it shows how
many subdirectories exist beneath the file.  There are always at least two.

The third column shows the username of the user who
owns the file.  In most cases this should be your username.

The fourth column shows the size of the file in "bytes."
In a text file, this is the number of characters in the file.

The fifth column shows the date when the file was last modified.
If a file has never been modified, it shows the date it was created.

The final column shows the name of the file.

You can use other options on the @b(ls) command to get it to show
you other information about your files.

To get a long listing of all the files in a directory, you would
enter @i(ls -la).

@b(-F for Type)

There are different types of files:  text files, files that are
directories to more files, and executable binary files.  Often,
you need to know the type of the files being listed.  The @p(-F)
(note, @i(uppercase) F) will show this:
@example[
host%  ls -F
Mail/    a.out*   myfortpgm.f   welcome
]
Notice the suffix characters / and * that are now displayed.  These
characters are NOT part of the filename.  The / character means
that the file is a directory.  The * character means that the file
is an executable binary or a shell script.
Nothing means either a plain text file,
or that Unix cannot recognize the type of the file.

@subsection(To See the Contents of a File:  cat and more)

There are two commands that will show you what's in a file:  @p(cat) and
@p(more).  @b(Cat) is simpler, but most people use @b(more).

@b(cat)

@b(cat) (short for "catenate"), types the contents of a file to your screen.
The format of the commands is:  cat @i(filename).  For example:
@example[
host%  cat .login
stty dec 
setenv PATH /usr/athena:/usr/new:/usr/new/mh:
            /usr/ucb:/bin:/usr/bin:/usr/local:~/Bin:/usr/games:/usr/hosts
setenv VISUAL /usr/athena/xemacs
setenv EDITOR /usr/athena/xemacs
setenv MORE -cs
set ignoreeof
host%
]
If the file is very long, it will zip by you on 
the screen faster than you can read it.
Use CTRL-S to make the output pause
and CTRL-Q to start it up again.  Use
the @b(more) command to avoid this.  (To cancel a @i(cat) command
and stop its output at any time, enter CTRL-C.)

=== MOVE THIS SECTION TO A TROUBLESHOOTING SECTION ===

@begin(description)
@multiple[
@i(Problem:)@\@i(I "catted" a file, but I got a lot of gobble-dee-gook and
          the terminal acted stranged, beeping a lot.)

          Some kinds of files are "unprintable."  They contain data in
          a format that cannot be displayed on a terminal screen.
          @p(Binary) files (the ones @i(ls -F) shows with a * suffix) are
          not printable.  @p(Directory) files (@i(ls -F) shows with / suffix)
          are not very printable.  It is very common when you start
          out to say @i(ls) when you meant @i(cat) and @i(cat)
          when you meant @i(ls).
]
@end(description)

@b(more)
 
The @p(more) command displays a file's contents one screen at a time,
pausing after every screenful so that you can read it.  The format
is:
@display[
host%  more @i(filename)
]

Once @i(more) has filled up a screen, it will not display further
until you type one of the following responses:
@display[
@tabclear
@tabset(2.5 inch)
SPACEBAR@\give me the next screenful
RETURN@\give me one more line
CTRL-B@\back up a page
/@i(word)RETURN@\skip forward until you find @i(word)
q or CTRL-C@\quit, I've seen enough
]


@b(More) does not display binary and directory files.  There
are subcommands to browse through a file for specific
words, or invoke a text editor to edit the file.  ===GIVE REFERENCE FOR THESE
SUBCOMMANDS, DO YOU MEAN SEARCHING, SCANNING?? ===

=== THIS IS AN IDEAL TIME TO SLIP IN MORE ON "REDIRECTING OUTPUT" MATERIAL ===

@b(More) is a Unix @b(filter).
Many other Unix commands "@b(pipe) their output through @i(more)."  
Instead of giving you their output directly, (where
it may zip past faster than you can read it),
they send it through @i(more) first so that it will be
under your control.  The @i(man) command that peruses online
documentation about Unix does this.

You, too, can "pipe things through @i(more)."  Whenever you enter a
command and its output is too copious and rapid to manage, cancel
the command with CTRL-C and reenter it like this:  
@example[
host% @i(command) | more
]
The | is the "pipe" character.  For example, if you have collected
hundreds of files, you could pipe the output of @i(ls) through @i(more):
@example[
host%  ls -l | more
]
Look at @i(man more) to learn more about its powers.


@section(Delete a File)

It is a good idea to delete unnecessary files.  This practice keeps you within
your storage quota, TO BE DISCUSSED IN SECTION/CHAPTER ???.  

The command to delete a file is @p(rm) (short for "remove"):
@example[
host%  rm easyfile 
host%
]
Unix doesn't verify the deletion, it just prompts for the next command.
You can put more than one name on the line.  You can use wildcards
(with caution!) to delete whole classes of files.  The most
catastrophic mistake you are likely to make is:
@display[
host% rm *
]
which deletes @b(all) your files!

@section(Copy a File)

The @p(cp) command copies files:
@example[
host%  cp  fromfile tofile
host%
]
Unix copies from the existing @i(fromfile) to the new @i(tofile).
If @i(tofile)
already
exists, it will be overwritten.  Again, Unix does not verify the copy.
INSERT TEXT ON COPYING FILES FROM ONE MACHINE TO ANOTHER HERE.


@section[Rename (Move) a File]

Use the @b(mv) (move) command to rename a file.
@example[
host%  mv fromfile tofile
host%
]
Unix renames @i(fromfile) to @i(tofile), in effect "moving" it from one file
to another.  If @i(tofile) already exists, it is overwritten.  As ever,
Unix does not confirm that it has done the operation.
WHAT ABOUT SIMPLY MOVING A FILE, AND KEEPING THE OLD NAME?

@section(Who Can Read Your Files?)

=== INSERT MORE ON ACCESS MATERIAL ===

This issue of who can see and do what to whose files is called @b(file
protection) or @b(mode).  You are the only person who can create, read,
modify, delete, and list the files in your own HOME directory.


Although the Unix system file security
mechanism safeguards your files, the
Unix file security mechanism is fairly easy to break.  This
"lock picking" ability is to be found in abundance at MIT.  Athena
policy on file security is:
@begin(text, leftmargin +5, rightmargin +5, above 2)
If you have data that @i(must) be private, @i(do not) keep it
on Athena.  If you have files that you cannot stand to lose (like
your thesis), then keep backup copies on floppy disk.  The free
Athena document @i(Transferring Your Files between Athena
and PC/XTs) explains how to do this.
 
=== TROUBLESHOOTING:  RUNNING OUT OF FILE SPACE/ DISK QUOTA ===
