In 1969, Ken Thompson of Bell Laboratories wrote the first version of Unix.
In 1973, Ken Thompson teamed up with Dennis Ritchie and they rewrote the Unix kernel in C.
multitasking--multiple programs can run at one time
multi user--more than a single user can work on one machine
There are many different implementations of Unix. They all have subtle differences in the way that they operate.
A few commercial implementations available in the CS Department are:
A few Linux distributions are the following. Some are free. Others the user must pay for a support contract.
Unix is organized at three levels:
“The UNIX kernel is built specifically for a machine when it is installed. It has a record of all the pieces of hardware it needs to talk to and knows what languages they speak (how to turn switches on and off to get a desired result).” http://www.extropia.com/tutorials/unix/kernel.html
The Unix shell provides a user interface. “The most basic UNIX shell provides a 'command line' which allows you to type in commands which are translated by the shell into kernel speak and sent off to the kernel.” http://www.extopia.com/tutorials/unix/shells.html
These provide additional functionality to the operating system. To see some tools that you have access to check out: /bin or /usr/bin
There are several different shells, they offer their own advantages and disadvantages. For instance, some allow for auto completion using the tab key; others don't.
A few common shells are the following:
For more on shells, click here.
To see what shells exist on your current Unix system, try the following command:
$ cat /etc/shells
Before you get a shell, you identify yourself with a login name and password. That login name is looked up in a file called /etc/passwd, which describes each user's account. More specifically, it tells your unique numeric ID, principal group ID, general information, home directory, and shell.
Try the following command:
$ cat /etc/passwd | grep yourusername
The format of the data in the /etc/passwd file is
Note, each of these attributes are separated by a : (colon). The last attribute on the line is your shell.
If you are feeling daring you can change your shell with the chsh command.
More information about /etc/passwd can be found here.
Although you can do a lot with a graphical user interface (GUI), it is often necessary to execute commands on the command-line. The basic format is:
prompt$ command-name options arguments
hercules% g++ -c main.cpp
a037094% ls -l
A summary of a few commands is provided in tabular format here:
|ssh||ssh firstname.lastname@example.org||Secure Shell (ssh) enables you to log in, execute commands, and run applications on a remote system.
SSH encrypts any communication between the remote user and a system on your network.
scp input.txt email@example.com:CS330lab1/
scp -r CS330 firstname.lastname@example.org:classes/
With Secure Copy (scp) you can copy files between the remote host and a network host. scp actually uses ssh to transfer data and employs the same authentication and encryption.
This first example copies the file input.txt from a users current directory to the user smithj's CS330lab1 directory, located on the hercules host.
|touch||touch myfile||Update the access and modification time of "myfile". If "myfile" does not exist, create it.|
|mkdir||mkdir reports||Creates a directory named "reports"|
|rmdir||rmdir letters||Erases a directory named "letters"|
rm -r mydir
Erases a file named "myfile"
Erases the directory "mydir" and any contents/subdirectories in it
Lists working directory with trailing characters for file types. Most common are / for directory and * for executable.
Lists all files including "hidden files"
Lists files with permissions, owner, group, time stamp
List the files inode number--a unique number used by the system to identify a specific file.
List files by time last modified.
Changes to the "reports" directory, making it the working directory.
Changes back to the home directory
Moves you up one directory level
|pwd||pwd||Print Working Directory - prints full path to current directory.|
cp lab1 mylab
cp lab1 mydirectory
cp lab1 mydirectory/mylab
cp -r mydirectory dirname
Copies file "lab1" to "mylab" file
Copies "lab1" in your working directory to "mydirectory"
Copies "lab1" to "mydirectory" and renames it "mylab".
Copies "mydirectory" and all its contents into "dirname".
mv lab1 lab2
mv lab1 labdirectory
mv lab1 labdirectory/newfile
mv labdirectory newdirectory
Renames "lab1" to "lab2"
Moves "lab1" to the "labdirectory"
Moves "lab1" to the "labdirectory" and renames it "newfile"
Renames a whole directory to a new directory name
g++ -o prog_run main.cpp
g++ -o prog_run main.o part1.o part2.o
compiles and links "main.cpp", calls the executable "prog_run"
compiles "main.cpp" (creates the object file)
links the object files (when you have different files), calls the executable "prog_run"
For another summary of Unix commands, click here.
For a Unix tutorial, click here.
Each file and directory in Unix contains a set of permissions that determine who can access it and how. There are three levels of access to set:
The ls command with the -l option allows you to view a file's permissions (among other information).
$ ls -l mydata -rw-r--r-- 1 chris weather 207 Feb 20 11:55 mydataThe breakdown of this information is as follows:
|File Type||Permissions||Number of Links||Owner Name||Group Name||Size of File in Bytes||Date and Time Last Modified||File Name|
|-||rw-r--r--||1||chris||weather||207||Feb 20 11:55||mydata|
Right now, the owner of mydata has read and write permissions, and the group, and the world have read permissions. How do I know? The permissions are organized in groups of three:
What would the following permissions represent?
Again it comes down to the /etc/passwd file. In this file, you have a unique numeric id, and a principle group id (also numeric). When you create a file, your unique numeric id and principle group id are assigned to that file. If there is a match of these numbers, then you will have specific permissions (according to whether you are user/group/world).
You have a principle group id, but you may also belong to other groups that are not your principle group. To know what groups you belong to, try the following command:
This command gets its information from the /etc/group file as well using your principle group id.
To set permissions, you use chmod. There are two main usages of chmod:
Symbolic Permission Mode:The general format for using the symbolic permission mode is the following:
chmod 'access class' operator 'access type' filenameFor example, this would add executable access for the user:
$ chmod u+x testfileThe following summarizes the values of "access class", "operator", and "access type" in the above syntax:
Given a base permission of -rw------ for a file called "myfile", what would the resulting permission be after the following chmod calls?
Absolute Permission Mode
Another way to change permissions is by using a numeric (octal) code. Typically, you will use three octal numbers: one for the user, one for the group and one for other (world).
The syntax for using chmod in absolute permission mode is:
chmod 'octal permissions' filenameFor example:
$ chmod 744 myfileEach of the three octal digits represent the read, write, and execute permissions for the user, group, and world respectively.
The following table summarizes the octal digits and how the permissions are affected:
What would the permissions look like on "myfile" after the following chmod calls?
For more on chmod click here
You can give a file more than one name using the ln command. You might want to reference a file using different filenames to access it from different directories. The added names are often referred to as links.
These links are similar in concept to shortcuts in windows
There are two kinds of links:
A hard link appears just like a file or directory, not a link. Hard links have a disadvantage in that they only work within one filesystem. In other words, they don't work between mounted filesystems. A hard link only refers to the original file. If the original file is deleted no information will be lost because the file is kept as long as there is at least one link to it.
To create hard link, you use the ln command with two arguments: the name of the original file and the new (added) filename.
$ ln original-filename added-filename $ ln today weather
You can use the ls command with the -l command to find if a file has several links. The first number that comes before the user's name indicates the number of links.
In order to see what files are links of other files use the ls command with the -i option to list the files inode number. An inode number is a unique number used by the system to identify a specific file. If two filenames h ave the exact same inode number, they reference exactly the same file.
$ ls -i today weather lab1 1234 today 1234 weather 3976 lab1In the above example, today and weather reference the same file.
So far the links we have seen have be hard links. When viewed with a long listing (ls -l), the symbolic link holds the path name of the file to which it is linking. It is not a direct hard link, it stores information on how to locate a specific file.
To create a symbolic link, use the following syntax:
$ ln -s today weather
For more on the difference between hard and soft links, see this link: http://linuxgazette.net/105/pitcher.html