Basics

Discussion about gcc -ansi -pedantic -Wall

man gcc to see what is the meaning of the flags

-ansi = -std=c90 disables several GNU extensions (i.e. typeof, asm, inline etc.) also several extensions of c99 are not supported (like declarations in for loop's condition)

-pedantic makes gcc reject programs using forbidden extensions and some non compliant to -ansi (but not all) and issue any warnings accordingly

-Wall generate warnings about suspicious/questionable code (A well written program should not print any warnings when using this flag)

-Wextra even more warnings

File permissions

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
          

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)

chmod

chmod changes the permissions of a file/directory


              +-----------------------------+
              |         Permissions         |
              +-----------+--------+--------+
              |  execute  |   x    |   1    |
              +-----------+--------+--------+
              |   read    |   r    |   4    |
              +-----------+--------+--------+
              |   write   |   w    |   2    |
              +-----------+--------+--------+

              +-----------------------------+
              |    Numerical permissions    |
              +---+-------------------+-----+
              | # |    Permission     | rwx |
              +---+-------------------+-----+
              | 7 |       full        | 111 |
              +---+-------------------+-----+
              | 6 |  read and write   | 110 |
              +---+-------------------+-----+
              | 5 | read and execute  | 101 |
              +---+-------------------+-----+
              | 4 |     read only     | 100 |
              +---+-------------------+-----+
              | 3 | write and execute | 011 |
              +---+-------------------+-----+
              | 2 |    write only     | 010 |
              +---+-------------------+-----+
              | 1 |   execute only    | 001 |
              +---+-------------------+-----+
              | 0 |       none        | 000 |
              +---+-------------------+-----+
          

Examples

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 or chmod 600 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)

Notes

Directories must always have execute permission.

Files with execute and without read can still be executed but not read.

The directories with your assignments should never be readable by other users.

References:

Authored by: Foivos S. Zakkak


Last Modified: 22-06-2015 14:34