Two Primary Kernel Subsystems

  1. File System: Deals with all input and output
  2. Process Management: Deals with programs and program interaction

Note: UNIX variants have slightly different implementations of various subsystems.

Unix File Types

The UNIX filesystem contains several different types of files:

Three Default I/O Channels:

Interprocess Communication:

Remember: File types aren’t determined by extension on UNIX.

UNIX File Names

On File Names:

Hidden Files: Files that begin with a dot (.)

Reserved Filenames:

UNIX Pathnames

Pathnames: Specify where a file is located in the hierarchically organized file system.

Two Kinds of Pathnames:

Linux File System Hierarchy Standard (FHS)

Directory Tree: All the files in the UNIX file system are organized into a multi-level hierarchy.

Linux File Hierarchy Structure (FHS): Defines the directory structure and contents in UNIX-like operating systems.

General FHS for Linux

Remember: The /usr variants of folders that can be found under root contain higher-level versions of their counterparts!

Fundamentals of Security (Groups)

UNIX is a multi-user system.

UNIX systems have one or more users, identified by numeric uid and username.

Command: id lets you view your uid, default groups, and which groups your belong to.

Unix File/Directory Permissions

Every file/directory has:

  1. A single owner.
  2. An association with a single group.
  3. A set of access permissions associated with it.

Permissions lets us answer questions like:

On Access Permissions

Permission For a File For a Directory
read Contents can be viewed Contents can be listed, but not searched
write Contents can be changed or deleted File entries can be added or removed
execute File can be run as a program Directory can be searched, and you can cd to it

Three Types of Permissions:

  1. Read (r): Process may read contents of file, or list directory contents.
  2. Write (w): Process may write contents of file, or add/remove directory contents.
  3. Execute (x): Process may execute file, or open files in directory or subdirectories.

Three Sets of Permissions:

  1. User (u): Permissions for owner
  2. Group (g): Permissions for group (1 group per file)
  3. Other (o): Permissions for everyone on the system.

Note: Every user is responsible for controlling access to their files and directories.

Viewing File Permissions

When using ls -l (long listing), file permissions are given in the following format—

—which are displayed as: -rwxrwxrwx - The first character shows file type: 1. File: - 2. Directory: d 3. Link: l - If a r, w, or x is replaced by a -, that permission is denied for that respective set. - Starting after the file type character, the: * First RWX triplet are for the user owner, * Middle RWX triplet are for the group, and * Last RWX triplet are for others.

Examples: Reading ls -a

-rwxr-xr-x 1 larry larry 15480 Dec 28 23:16 a.out

drwxr-xr-x 1 larry larry 0 Dec 28 23:17 directory

-rw-r--r-- 1 larry larry 90 Dec 28 23:16 source.c

Utilities for Manipulation File Attributes

Permission Settings for Octal Mode

Permission settings use octal numbers:

Permission Binary Octal
r 100 4
w 010 2
x 001 1
None 000 0
Example: Converting permissions to octal equivalents
Permission Binary Octal
rwx rwx rwx 111 111 111 7 7 7
rwx r-x r-x 111 101 101 7 5 5
rw- r-- r-- 110 100 100 6 4 4
r-- --- --- 100 000 000 4 0 0
Example: Using chmod with symbolic access mode ({u,g,o}/{r,w,x}) and octal access mode

Format: chmod [ugoa] [+-=] [rwx] [file/dir]

$ chmod +x daemon.sh
$ chmod o -r unreadable.txt
$ chmod a=r-x file
$ chmod go-w unwriteable.txt
$ chmod g:cs2600-x unexecutable
$ chmod 600 my_file
$ chmod 755 our_file