Controlling Ownership and Read/Write Access


Changing groups (using the newgrp command) does not change your directory path. Use the cd command to change your directory path.

Similarly, changing directory paths, does not change groups.

If you work within groups, you should check the ownership of files periodically (perhaps once a month). If you accidentally create files intended for a group using the default group associated with your userid (for example, employee) those files will be deleted when you leave the College, unless you change the ownership.

Determine what groups you belong to

Use the groups command to display the ids of the groups you belong to.

Change to use files and directories in a different group

Use the following command:
     newgrp groupid
to change to work with files and directories owned by the specified groupid. Your userid must belong to the group.

If you have been working with a group id and wish to return to the files owned by your personal userid, type exit.

Check ownership and permission

Occasionally, check the ownership and permissions for your files, using the following command:
     ls -l
Typing ls -l displays a list of directory contents that includes: file type, security permissions, owner, size, creation date, and file name. Here's a sample:
% ls -l /html/depts/epid/bubonic
total 9138
drwxrwxr-x   2 schulz   epid           512 Jul 18 15:56 history/
-rw-rw-r--   1 frank    faculty     478082 Jul 18 15:56 imgmap.gif
-rw-rw-r--   1 schulz   epid         17942 Jul 18 15:56 index.html
-rw-rw-r--   1 frank    epid        457224 Jul 18 15:56 logo.gif
drwxrwxr-x   2 jones    epid           512 Jul 18 15:56 pathology/
-rw-rw-r--   1 jones    epid         22284 Jul 18 15:56 work-in-progress.html
In this example, the group epid owns all the files except imgmap.gif, which belongs to the personal userid of frank, a faculty member, and will be deleted when he or she leaves the University.

A "d" in the first column (as in history/) indicates a directory; a dash ("-") indicates a file; an "l" indicates a "link" (for example:

lrwxrwxrwx   1 frank    faculty      18 Aug 14 12:56 public_html@ -> /html/home/frank/
shows that public_html is a link to /html/home/frank/, which is on the computer.

The next nine columns, in three groups of three, define read (r), write (w) and execute (x) permission for your userid (the first three columns), for the members of the group to which the files or directories belong (the second three columns), and for anyone logged onto the system (the third three columns).

Almost always, you want to have 'rw-' for your (the owner's) data files and 'rwx' for your programs and directories. And, for everyone, you'll probably want either 'r--' or '---', depending on whether or not it's OK for people to read your files, and 'r-x' for your directories.

If you work within groups, look closely to see which directories and files you want to keep control over and which you will allow the group to write to. Use the chmod command, described below, to change permissions.

Change permissions for files

Use the command chmod to change the read, write, and/or execute permissions of files.

The command has three parts:

  1. Whose permissions you want to change:

    g for the group
    a for all

  2. What you want to change them to:

    + to add permission
    - to remove permission
    r read
    x execute

  3. Which files to change; you can specify one file name, a list of file names, or an asterisk (*) -- all the files in the current directory,
Here are a few examples:
     chmod g+r homework.html exams.html
allows the group to read the files homework.html and 
exams.html, but not write to them

     chmod g+rwx openinfo   
grants read, write, and execute access to anyone in the group to files 
in the directory openinfo

Use numeric codes to set multiple access permissions. For example, 664 is the equivalent of setting both g+rw and a+r and 644 is the equivalent of setting both g+r and a+r. Similarly, 775 is the equivalent of setting both g+rwx and a+rx and 755 is the equivalent of setting both g+rx and a+rx. For example:
     chmod 664 * 
allows members of the group to read and write and everyone to read 
all the files in the current directory

     chmod 755 images
allows members of the group and everyone to read and execute the 
directory images (Web directories should be marked executable)

Change group ownership of files

Use the following command to change the group ownership of a file:
     chgrp newgroup filename
where newgroup is name of the group you want the file associated with and filename is the name of the file. For example:
     chgrp culinary salads
changes ownership of the file salads to the group culinary

     chgrp culinary *
changes ownership of all the files in the current directory to culinary

[Web Weaver] [CCSFweb] [CCSF Info] [Events] [Site Index] [Help]