An operating system is the software that controls the computer. When you turn a computer on, the operating system is loaded into memory and basically takes charge providing services to you and to the programs you use. The functions of the operating system fall into two broad categories:
it provides an interface that allows the user to interact with the machine;
it manages the hardware resources of the computer (CPU, memory, storage devices, input/output devices, other peripheral devices). For example it is in charge of launching programs and managing memory while they are running, it manages files on disk (opens and saves documents) and other auxiliary storage devices, it detects input from the keyboard or mouse and sends the input to the program, and it is in charge of sending output to the monitor or printer. In addition it manages the sharing of resources by multiple programs and users and is in charge of the security of the system.
The operating system we will use in this course is Linux, an open source implementation of the Unix operating system. This handout gives you an overview of a few Linux/Unix concepts.
The computers in the third floor Trexler lab are set up to run either Linux or Windows - the two operating systems are stored in separate partitions on the hard drives of the computers. Many system files and all student and faculty home directories are stored on a Linux server named cs.roanoke.edu, commonly known as CS.
To start up a computer one must go through a process called booting the system. During the boot process, the system checks the hardware on the machine and then loads the operating system -- brings it from auxiliary memory (usually a hard disk) into main memory (RAM). The lab computers are dual boot systems that can load either Windows or Linux. During the boot process, the system pauses briefly and displays a graphical menu asking which operating system to load. The default is Windows, but you can direct it to load Linux instead. The in-class portion of the lab gives instructions for booting the machines into Linux.
The user interface for the version of Linux in the labs is a public domain X-Windows system with a desktop managing program called Unity. This desktop environment is similar to that in Microsoft Windows and Macintosh computers. It is a GUI environment where one interacts primarily by pointing and clicking with a mouse.
An alternative to a GUI interface is a command line interface where one interacts with the operating system by typing in commands. Such interfaces are often favored by programmers because, once you learn the commands, it is faster and more efficient. In UNIX systems, the command line environment is called the shell. Actually the shell is an interface program that interprets operating system commands you type in and executes them (if the command was correct; otherwise you are given an error message). Learning the syntax of basic shell commands is the first task in becoming a skilled user of Linux. In Linux, shell commands are typed into a window called a shell window or a terminal window (also called an xterm).
From a user's perspective, the operating system function he/she is most aware of (other than the user interface) is that of managing the storage of data on auxiliary memory (typically disk). User data (such as a research paper or a program) and system data (such as password information and the machine code for carrying out operating system commands) are stored in files. (The files are called documents in Windows.) The operating system is responsible for saving files, opening files, deleting files, and letting the user organize the files. In a GUI environment this is done by various combinations of pointing and clicking and dragging and dropping. Files are generally organized in folders or directories. Such an organization is logically a hierarchical, tree structure with one main folder (directory) with other folders inside of that, and each of those may contain other folders and documents. This is the organizational structure of the Unix File system. Most files are either regular (also called ordinary) files or directories. Regular files (usually just called files) contain text, programs, or other data. Directories contain names and addresses of other files and directories. Some special directories are as follows:
the root directory is the directory at the top level of the file system hierarchy (the root of the tree). It is denoted by the slash (/) character. Within the root directory are many important subdirectories including
bin (which contains the executable files for many system commands)
home (which contains the "home" directories of individual users on the system)
usr (which contains many system files, usually in subdirectories such as usr/bin)
etc (which contains system data files such as password files and files containing information about printers)
Each subdirectory may in turn contain more files, both regular and directories.
your current working directory (or present working directory) is the directory you are in at a given point (you are always somewhere in the file system!). This directory can be referenced by the period (.) character.
the directory up one level in the tree structure from the current working directory. This directory is denoted by two periods (..).
each user has a home directory which is the top level of the user's personal file structure on the system and can always be referenced using the tilde character followed by the username, ~username. The owner of a home directory may refer to his/her home directory with the tilde character alone (without the username).
public_html -- the default name on a Unix system for a subdirectory of a user's home directory that contains files publicly accessible from the Web
In general, a file can always be referenced either using its full (also called absolute) pathname or a pathname that is relative to the current working directory. An absolute pathname gives the path of the file through the tree starting at the root /. Subdirectories along the path are separated by slashes. A relative pathname gives the path from the current working directory.
Example: Consider the file named hello.py in the lab2 subdirectory of a student with username bozo (see the diagram above).
Full pathname: /home/students/bozo/cs120/labs/lab2/hello.py
Full pathname using abbreviation for bozo's home: ~bozo/cs120/labs/lab2/hello.py (could be used by any user in the system)
Full pathname bozo can use: ~/cs120/labs/lab2/hello.py
Relative pathname if the present working directory is bozo: cs120/labs/lab2/hello.py
Relative pathname if the present working directory is cs120: labs/lab2/hello.py OR ./labs/lab2/hello.py (remember . means current directory)
Relative pathname if the present working directory is lab2: hello.py
Relative pathname is the present working directory is lab1: ../lab2/hello.py (remember .. means one level up from current directory)
The hierarchical file structure used in Unix is similar to that used in Window and the earlier MS-DOS systems. (In fact, MS-DOS borrowed its file structure and many operating system commands from Unix.) One difference however is that Unix does not use the idea of drive letters for physically different disk drives (for example, A for the floppy drive and C for the hard drive). There is only one system with each separate physical drive mounted under some directory. For example, the lab computers actually mount the /home directories from CS (the Linux server), while the rest of the file system is stored locally, but you can't tell this as the user -- it looks like it's all on the same machine. Hence, the one large logical file structure can physically reside on several different computers.
The shell commands we will use are those that let you do things such as create directories, change from one directory to another, see a listing of files in a directory, copy files from one directory to another, and print files. Each command has a name (usually fairly short such as mkdir for "make directory") and usually has one or more arguments. For example, to create (make) a directory named myDirectory as a subdirectory of your current directory (where you are now!) you type the following into a terminal window:
mkdir myDirectory
The name of the directory you want created is the argument.
A cheat sheet of typical Unix commands is provided for you on the course webpage
Every file or sub-directory in a directory has a list of permissions assigned to it. Three sets of permissions are assigned: one to the owner of the file, another to the group (users may be put in groups), and the third to all others. These permissions define who has the right to look at ("read"), modify ("write"), or execute that file or directory. Permissions for a particular file or directory are shown as a sequence of 10 characters:
The first character indicates the type of file (usually a minus symbol -, meaning a regular file, or a d, indicating a directory),
the next three characters give the read/write/execute permissions of the owner,
the next three give the read/write/execute permissions of the group, and
the last three give the read/write/execute permissions of all other users.
Some examples are
-rw-r--r--
and
drwx--x--x
The first example indicates a regular file where the owner has read
and write permissions (the r and w) but not execute permission (the -)
and both the group and all others have only read permission. The
second example indicates a file that is a directory where the owner
has read, write and execute permissions but the group and others have
only execute permission. One can see the permissions on files by
using the ls command with the l (the letter "el") option (type ls -l
to see permissions for all files in a directory or ls -l filename
to
see permissions on a given file).
What is the full pathname of the file my_page.html in the sample file system shown on this handout?
What is the relative pathname of my_page.html if you are currently in the directory cpsc?
What is the shell command to see a listing of all files in the current directory if you want to also see information such as date of creation and file permissions?
The mkdir command has one argument, the name of the directory you want to create. How many arguments does the cp (copy) command have and what does each represent?
Suppose the permissions on a file are -rw-r-----
. Who, other
than the owner is allowed to read the file? Who is allowed to change
the file (write)?