Thursday, October 27, 2011




Universe Editor Commands

 The EDITOR can be called with the following formats:
ED                           (file and record id's will be prompted)
ED file                   (record id's will be prompted)
ED file id               (edit the record 'id' in 'file')
ED file id id...      (edit multiple id's in 'file')
ED file *                (edit all records in 'file')
 SELECT ...            (may precede 'ED file' command)

 Special ASCII characters may be entered as:
      ...^nnn...  where nnn is the decimal character code
      ...^^...    will enter a single UP ARROW character.
  An Editor command  ending with a  '?' will be placed on the command stack, but will not be executed.

The following commands may be used in the Editor:
A                             - Do the last 'A any' (APPEND) command again.
A any                     - APPEND 'any' to this line.
ABORT                  - Toggle command execution ABORT between ON and OFF.
B                              - Set the current line pointer to the BOTTOM line.
B any                     - BREAK the current line after 'any' into two lines.
BLOCK                   - Toggle BLOCK operation verification between ON and OFF.
C                             - Do the last 'CHANGE' command again.
C///                       - CHANGE one or more lines.
Formats permitted are:
C/from/to     C/from/to/#
C/from/to/G   C/from/to/#G   C/from/to/G#
C/from/to/B   C/from/to/BG   C/from/to/GB
where  / - is any delimiter character.
from - is the character string to be replaced.
to - is the character string to substitute.
# - is the number of lines to CHANGE.  (The default is one)
G - is the  letter 'G' (global)  CHANGE  all instances  in  line.
B - is the letter 'B',  CHANGE  all lines in the  defined  BLOCK.
CASE                      - Toggle CASE mode between ON and OFF. When CASE is ON,  input will remain in the
  case as typed. When CASE is OFF,  input will be UPCASEd for case insensitivity support.
  TCL CASE insensitivity must be ON to use CASE.
CAT any                - CONCATENATE the next line onto the current line, separated by 'any'.
COL                        - Display relative COLUMN POSITIONS on the CRT.
COPY                    - COPY a BLOCK (see '<' and '>' ), source block is unchanged.
D                            - DELETE the current line.
D#                           - DELETE '#' lines starting with the current line.
DE            - DELETE the current line.
DE#                        - DELETE '#' lines starting with the current line.
DELETE                  - DELETE the entire record from the FILE.
DROP                    - DROP (DELETE) all lines in the defined BLOCK (see '<' and '>' ).
DUP                       - DUPLICATE the current line.
DUP#                    - DUPLICATE the current line '#' times.
EX                           - EXIT the editor (same as QUIT).
F                              - Do the last 'FIND' command again.
any                        - FIND the next line that starts with the string 'any'.
F# any                   - FIND the next line that  contains  the string 'any' starting in column '#'.
FANCY.FORMAT               - Format a BASIC program to show logical structure by indenting.   This command is
   similar to the FORMAT command except that it handles comments and labels
  differently.
FD                           - Delete the entire record from the file (same as DELETE).
FI                            - FILE the record (same as FILE).
FIL                          - FILE the record under the originally specified name.
FILE name           - FILE the record under the specified 'name'.
FILE f name         - FILE record 'name' in file 'f'.
FORMAT              - FORMAT a BASIC program to show logical structure by indenting.
G#                          - GO TO line '#' (set line pointer to line '#';  'G' is optional).
G<                          - GO TO line defined by the beginning of the current BLOCK.
G>                          - GO TO line defined by the end of the current BLOCK.
HELP                      - Prompt user to display HELP information on the CRT.
HELP any              - Display HELP information on CRT for 'any'.
I                               - INSERT new lines AFTER the current line.  Prompt for successive lines of INPUT  until
  NULL input. An INPUT line of a single space will store a NULL line.
IB                            - INSERT new lines BEFORE the current line.  Prompt for successive lines of INPUT until
  NULL input. An INPUT line of a single space will store a NULL line.
I any                      - INSERT (INPUT) the line 'any' AFTER the current line.
IB any                    - INSERT (INPUT) the line 'any' BEFORE the current line.
L                              - Do the last 'LOCATE' command again.
L any                      - LOCATE the next line that contains the string 'any'.
L#                           - LIST '#' lines  starting with  the current  line on to the  CRT.
LOAD name        - LOAD  the record  'name' from the current FILE; line #'s will be prompted.
LOAD f name     - LOAD the record 'name' from file 'f'; line #'s will be prompted.
M            - Do the last 'MATCH' command again.
M any                    - Search for next line that MATCHES the pattern 'any'.
MOVE                   - MOVE a BLOCK (see '<' and '>' ); source block is deleted.
N                             - Go on to next selected record; used when  SELECT list is active.
OOPS                    - RESTORE the  record to the  condition prior to the  last change.
P                             - PRINT on CRT the same number of lines  specified with last 'P#'.
P#                            - PRINT on CRT '#' lines starting with the current line.
PB                           - PRINT on CRT all lines in the defined  BLOCK (see '<' and '>' ).
PE                           - The PE command allows a user to execute  any legal PERFORM command from within
                                  the editor.  Upon completion of the command, control will be returned to the editor.
PERFORM            - The PERFORM command allows a user to execute any legal PERFORM command from
                                   within the editor.  Upon completion of the command, control will be returned to the
                                  editor.
PL#                         - PRINT the current line and the next '#' lines; do not change the current line pointer.
PL-#                       - PRINT  the current  line and the prior '#' lines;  do not change the current line pointer.
PO#                       - POSITION  current line  pointer to line '#'  ('PO' is optional).
PP#                        - PAGE.PRINT a window of '#' lines around the current line; do not change the current
                                  line pointer.
Q                             - QUIT - EXIT the editor.
QUIT                      - QUIT - EXIT the editor.
R                             - Do the last 'REPLACE' (R any) command again.
R any                     - REPLACE this line with 'any'.
R///                       - CHANGE one or more lines (same as C/// command.)
RELEASE               - RELEASE the update record LOCK for this file.
SAVE                     - SAVE  (FILE)  a copy of  this  record  under the original  name.
SAVE name         - SAVE (FILE) a copy of this  record under the  specified  'name'.
SAVE f name      - SAVE (FILE) a copy of this record as record 'name' in  file 'f'.
SEQ///                  - Generate SEQUENTIAL numbers. Formats permitted are:
                                                SEQ/from/start/#   SEQ/from/start/#/inc
                                                 where      / - is any delimiter character.
                                                 from - is the optional character string to replace.
                                                start - is the starting sequential number.
                                                  # - is the number of lines to SEQUENCE, or the letter 'B'
 (sequence in defined BLOCK).
inc - is the optional increment (default is one).
SIZE                        - Display the SIZE of this record (# of LINES/FIELDS, # of BYTES).
SPOOL                  - SPOOL entire record to PRINTER.
SPOOL#                - SPOOL '#' lines to the PRINTER.
SPOOLHELP        - SPOOL the HELP listing to the default PRINTER.
STAMP                 - INSERT a 'last modified' stamp into the record, which begins with a '*' (for BASIC
                 'comment'), and contains the account name, LOGIN name  (if  different  from account
                 name), date  and  time.  Used to mark when record was last changed.
T                              - Set current line to the TOP (before first line).
UNLOAD name - UNLOAD to record  'name' in  this  FILE;  line #'s are prompted.
UNLOAD f name- UNLOAD to  record 'name' in  file  'f';  line #'s are  prompted.
X                             - EXIT (QUIT) from the editor and abandon an active SELECT list.
XEQ                        - The XEQ command allows a user to execute any legal PERFORM command from
   within the editor.  Upon completion of the command, control will be returned back to
   the editor.
.A# any                 - Append  'any' to  stack command '#'.  The  default for '#' is 1.
.C#/s1/s2             - CHANGE string  's1'  to  string 's2' in stack  command '#'.  The default for '#' is 1. '/' is
  any delimiter character.
.D#                         - DELETE stack command '#'.  The default for '#' is 1.
.D name               - DELETE pre-stored command record 'name' from file '&ED&'.
.D f name            - DELETE pre-stored command record 'name' from file 'f'.
.I#                           - Prompt for  successive  command lines to INSERT at stack command '#' until null input.
                                   '#' defaults to 1.
.I# any                  - INSERT (INPUT)  'any' at command  stack '#'.  '#' defaults to 1.
.L#                          - LIST,  on the CRT,  the last '#' commands in the  command stack.  '#' defaults to 9.
.L name                                - LIST, on the CRT, the pre-stored command string in record 'name' in file '&ED&'.
.L f name             - LIST, on the CRT, the pre-stored command string in record 'name' in file 'f'.
.L f *                      - LIST, on the CRT, the names of the pre-stored command records in file 'f'.  'f' defaults
                                  to '&ED&'.
.R#                         - RECALL command '#' to  stack position 1 (moves command '#', does not copy it).
.R name               - RECALL pre-stored command record 'name' to the stack.
.R f name             - RECALL  pre-stored  command  record  'name' in  file  'f' to the stack.
.S# name             - SAVE commands, starting with command '#' and ending with command 1 in the stack,
                                  in record 'name' in file '&ED&'.
.S# f name          - SAVE commands, starting with command '#' and ending with command 1 in the stack,
                                  in record 'name' in file 'f'.
.S n s#,e#            - SAVE commands starting with command 's#' and ending with command 'e#' in the
  stack, in  record 'n' in file  '&ED&'. 
For example, '.S n 4,2' saves three commands, with  stack command #4 becoming
pre-stored command #1, in record 'n' in file '&ED&'.
.S f n s#,e#          - SAVE commands starting with command 's#' and ending with command 'e#' in  the
  stack,  in  record 'n' in file 'f'.
For example, '.S n 4,2' saves  three commands, with stack command #4 becoming
pre-stored command #1, in record 'n' in file 'f'.
.X#                         - EXECUTE stack command '#' and put it in stack position 1.
.X name               - EXECUTE the pre-stored commands in record 'name' in file '&ED&'.
.X f name             - EXECUTE the  pre-stored  commands in record  'name' in file 'f'.
.XK                         - EXECUTE KILL.  This command ABORTs a  pre-stored command string after execution is
                                  suspended by a PAUSE command.
.XR                         - EXECUTE RESUME.  This command RESTARTs a pre-stored command string after
                                  execution is suspended by a PAUSE command.
PAUSE                  - Is a pre-stored command string command  (i.e.  It is valid only within the pre-stored
  command string itself) that suspends command execution when encountered.  A '.XR'
  command restarts execution and a '.XK' command aborts execution.
LOOP #1 #2         - Is a pre-stored command  string command  (i.e.  It is valid only within the pre-stored
  command string itself) that repeats the sequence of commands beginning with
  command '#1' and ending with  the LOOP command itself, for '#2' iterations. Both '#1'
  and '#2' default to 1.
+#                           - Advance current line POINTER by '#' lines.
-#                            - Back up current line POINTER by '#' lines.
#                             - Set the current line POINTER to the '#' line.
<                             - Define the first line of a BLOCK (for COPY/CHANGE/DROP/MOVE/PB).
>                             - Define the last line of a BLOCK  (for COPY/CHANGE/DROP/MOVE/PB).
<>                           - Define first  and last line  of a  BLOCK (for  COPY/CHANGE/DROP/MOVE/PB).
^                             - Switch  UP ARROW  on/off to display  non-printing  characters as ^nnn  where  nnn  is
  the  decimal  equivalent  of  ASCII  code.
?                              - PRINT key parameters on the CRT.



Thursday, September 15, 2011

Understanding file permissions on Unix: a brief tutorial

Understanding file permissions on Unix: a brief tutorial

(For files on AFS fileservers, see below)


Every user on a Unix system has a unique username, and is a member of at least one group (the primary group for that user). This group information is held in the password file (/etc/passwd). A user can also be a member of one or more other groups. The auxiliary group information is held in the file /etc/group. Only the administrator can create new groups or add/delete group members (one of the shortcomings of the system). Every directory and file on the system has an owner, and also an associated group. It also has a set of permission flags which specify separate read, write and execute permissions for the 'user' (owner), 'group', and 'other' (everyone else with an account on the computer) The 'ls' command shows the permissions and group associated with files when used with the -l option. On some systems (e.g. Coos), the '-g' option is also needed to see the group information.
An example of the output produced by 'ls -l' is shown below.
drwx------ 2 richard staff  2048 Jan  2 1997  private
drwxrws--- 2 richard staff  2048 Jan  2 1997  admin
-rw-rw---- 2 richard staff 12040 Aug 20 1996  admin/userinfo
drwxr-xr-x 3 richard user   2048 May 13 09:27 public
Understanding how to read this output is useful to all unix users, but especially people using group access permissions. Field 1:   a set of ten permission flags.
Field 2:   link count (don't worry about this)
Field 3:   owner of the file
Field 4:   associated group for the file
Field 5:   size in bytes
Field 6-8: date of last modification (format varies, but always 3 fields)
Field 9:   name of file (possibly with path, depending on how ls was called)

The permission flags are read as follows (left to right)
position Meaning
1 directory flag, 'd' if a directory, '-' if a normal file, something else occasionally may appear here for special devices.
2,3,4 read, write, execute permission for User (Owner) of file
5,6,7 read, write, execute permission for Group
8,9,10 read, write, execute permission for Other
value Meaning
- in any position means that flag is not set
r file is readable by owner, group or other
w file is writeable. On a directory, write access means you can add or delete files
x file is executable (only for programs and shell scripts - not useful for data files). Execute permission on a directory means you can list the files in that directory
s in the place where 'x' would normally go is called the set-UID or set-groupID flag.

On an executable program with set-UID or set-groupID, that program runs with the effective permissions of its owner or group.

For a directory, the set-groupID flag means that all files created inside that directory will inherit the group of the directory. Without this flag, a file takes on the primary group of the user creating the file. This property is important to people trying to maintain a directory as group accessible. The subdirectories also inherit the set-groupID property.

The default file permissions (umask):

Each user has a default set of permissions which apply to all files created by that user, unless the software explicitly sets something else. This is often called the 'umask', after the command used to change it. It is either inherited from the login process, or set in the .cshrc or .login file which configures an individual account, or it can be run manually. Typically the default configuration is equivalent to typing 'umask 22' which produces permissions of:
-rw-r--r-- for regular files, or
drwxr-xr-x for directories.
In other words, user has full access, everyone else (group and other) has read access to files, lookup access to directories. When working with group-access files and directories, it is common to use 'umask 2' which produces permissions of:
-rw-rw-r-- for regular files, or
drwxrwxr-x for directories.
For private work, use 'umask 77' which produces permissions:
-rw------- for regular files, or
drwx------ for directories.
The logic behind the number given to umask is not intuitive. The command to change the permission flags is "chmod". Only the owner of a file can change its permissions.
The command to change the group of a file is "chgrp". Only the owner of a file can change its group, and can only change it to a group of which he is a member.
See the online manual pages for details of these commands on any particular system (e.g. "man chmod").
Examples of typical useage are given below:
chmod g+w myfile
give group write permission to "myfile", leaving all other permission flags alone

chmod g-rw myfile
remove read and write access to "myfile", leaving all other permission flags alone

chmod g+rwxs mydir
give full group read/write access to directory "mydir", also setting the set-groupID flag so that directories created inside it inherit the group

chmod u=rw,go= privatefile
explicitly give user read/write access, and revoke all group and other access, to file 'privatefile'

chmod -R g+rw .
give group read write access to this directory, and everything inside of it (-R = recursive)

chgrp -R medi .
change the ownership of this directory to group 'medi' and everything inside of it (-R = recursive). The person issuing this command must own all the files or it will fail.
WARNINGS:
Putting 'umask 2' into a startup file (.login or .cshrc) will make these settings apply to everything you do unless manually changed. This can lead to giving group access to files such as saved email in your home directory, which is generally not desireable.
Making a file group read/write without checking what its group is can lead to accidentally giving access to almost everyone on the system. Normally all users are members of some default group such as "users", as well as being members of specific project-oriented groups. Don't give group access to "users" when you intended some other group.
Remember that to read a file, you need execute access to the directory it is in AND read access to the file itself. To write a file, your need execute access to the directory AND write access to the file. To create new files or delete files, you need write access to the directory. You also need execute access to all parent directories back to the root. Group access will break if a parent directory is made completely private.

AFS Access Control Lists (ACLs)

Files on the central AFS fileservers all have the traditional Unix permissions as explained above, but they are also controlled by Access Control Lists (ACL) which take precedence. They provide access levels more flexible than the user/group/other attribute bits, but they work on the level of complete directories, not files. The command to set and list ACLs is fs.
"fs" is a big ugly command that does lots of things related to AFS filesystems depending on the arguments you call it with. For details see the man pages for: fs_setacl, fs_listacl, fs_cleanacl, fs_copyacl
For brief help, do (e.g.) "fs help setacl"
The default is to give the same permissions to a new directory as are on the parent directory. In practice, this is usually to give complete rights to the owner of the directory, and lookup rights to any other user (equivalent to execute attribute on a directory).
To render a directory private, the simplest command is:
fs setacl -d DIRNAME -clear -a MYNAME all
- replace DIRNAME with the appropriate directory name (or "." for the current directory, and MYNAME with your login name.
Check it with:
fs listacl DIRNAME
It should reply with:
Access list for DIRNAME is
Normal rights:
  USERNAME rlidwka
(see man fs_setacl for a description of the meaning of the flags "rlidwka")
To explicitly give public read/lookup access, use:
fs setacl -d DIRNAME -a system:anyuser read
This can be abbreviated to
fs sa DIRNAME system:anyuser read
If "fs" is not found, or the man pages are not found, your paths are not set up correctly. I recommend you run /usr/local/bin/mknewdotfiles to correct that.