You are on page 1of 34

What Is UNIX?

UNIX is a computer operating system. An operating system is the program that controls all the other parts of a computer system, both the hardware and the software. It allocates the computer's resources and schedules tasks. It allows you to make use of the facilities provided by the system. Every computer requires an operating system. UNIX is a multi-user, multi-tasking operating system. Multiple users may have multiple tasks running simultaneously. This is very different than PC operating systems. UNIX is a machine independent operating system. Not specific to just one type of computer hardware. Designed from the beginning to be independent of the computer hardware. UNIX is a software development environment. Was born in and designed to function within this type of environment. The "UNIX" trademark, previously owned by AT&T and then deeded to UNIX Systems Laboratories (USL), an AT&T subsidiary, passed to Novell when it acquired USL. After a brief period of negotiations with rival Unix vendors Sun Microsystems, Santa Cruz Operation, International Business Machines, and Hewlett-Packard, Novell granted exclusive licensing rights to the UNIX trademark to X/Open Co. Ltd., an Open Systems industry standards branding agent based in the United Kingdom.

History of UNIX

1969: Developed at AT&T Bell Labs in Murray Hill, New Jersey, one of the largest research facilities in the world. Created in an environment when most computer jobs were fed into a batch system.

Developed by researchers who needed a set of computing tools to help them with their projects and their collaborators. Allowed a group of people working together on a project to share selected data and programs.

1975: AT&T makes UNIX widely available - offered to educational institutions at minimal cost. Becomes popular with university computer science programs. AT&T distributes standard versions in source form: Version 6 (1975), Version 7 (1978), System III (1981). 1984 to date: University of California, Berkeley adds major enhancements, creates Berkeley Standard Distribution (BSD) 1984 to date: Many Berkeley features incorporated into new AT&T version: System V UNIX has become the operating system of choice for engineering and scientific workstations. Two variations maintain popularity today, AT&T System V based and the Berkeley Standard Distribution. Current versions (1/95)are System V release 4.2 .and 4.4 BSD Work is in progress to develop a Portable Operating System specification based on UNIX (IEEE POSIX committee).

UNIX Philosophy

Make each program do one thing well. Reusable software tools: 1 tool = 1 function Expect the output of every program to become the input of another, yet unknown, program to combine simple tools to perform complex tasks Prototyping: get something small working as soon as possible and modify it incrementally until it is finished Use terse commands and messages: reduces typing and screen output


Hardware independence o operating system code is written in C language rather than a specific assembly language o operating system software can be easily moved from one hardware system to another o UNIX applications can be easily moved to other UNIX machines. Porting is usually as simple as transfer of the source and a recompile Productive environment for software development

rich set of tools versatile command language UNIX is available at virtually all HPC centers, allowing researchers relative ease in utilizing the facilities at each center. Distributed processing and multi-tasking
o o

UNIX Components

Kernel o The core of the UNIX system. Loaded at system start up (boot). Memory-resident control program. o Manages the entire resources of the system, presenting them to you and every other user as a coherent system. Provides service to user applications such as device management, process scheduling, etc. o Example functions performed by the kernel are: managing the machine's memory and allocating it to each process. scheduling the work done by the CPU so that the work of each user is carried out as efficiently as is possible. accomplishing the transfer of data from one part of the machine to another interpreting and executing instructions from the shell enforcing file access permissions o You do not need to know anything about the kernel in order to use a UNIX system. These details are provided for your information only. Shell o Whenever you login to a Unix system you are placed in a shell program. The shell's prompt is usually visible at the cursor's position on your screen. To get your work done, you enter commands at this prompt. o The shell is a command interpreter; it takes each command and passes it to the operating system kernel to be acted upon. It then displays the results of this operation on your screen. o Several shells are usually available on any UNIX system, each with its own strengths and weaknesses. o Different users may use different shells. Initially, your system adminstrator will supply a default shell, which can be overridden or changed. The most commonly available shells are: Bourne shell (sh) C shell (csh) Korn shell (ksh) TC Shell (tcsh)

Bourne Again Shell (bash) Each shell also includes its own programming language. Command files, called "shell scripts" are used to accomplish a series of tasks. Utilities o UNIX provides several hundred utility programs, often referred to as commands. o Accomplish universal functions editing file maintenance printing sorting programming support online info etc. o Modular: single functions can be grouped to perform more complex tasks o

System V vs. BSD

AT&T distributes System V for their computers. System V is also the basis for several commercial implementations including: o Hewlett-Packard HP-UX o Apple AUX o Amdahl UTS o Cray UNICOS o IBM AIX. BSD, from the University of California Berkeley, has undergone extensive modification and enhancement in the university environment. BSD is available directly from UCB and in a number of commercial versions including: Sun, Apollo, DEC Ultrix, Gould UTX/32. System V and BSD contain a large set of commands in common. Some of these commands, however, support different options and have different default behaviors and output formats. ex: ls, stty, mail, grep Each version also has its own unique utilities. Some very common tasks, such as browsing a file, are performed by totally different utilities: System V uses "pg" whereas BSD uses "more".

This concludes the tutorial. Return to the Table of Contents

Logging On To The System

Before you can begin to use the system you will need to have a valid username and a password. Assignment of usernames and initial passwords is typically handled by the System Administrator or a "Computer Accounts" office. Your username, also called a userid, should be unique and should not change. Initial passwords can be anything and should be changed after your first login. To login to your account 1. Type your username at the login prompt. UNIX is case sensitive if your username is kellyk do not type KellyK . Press the RETURN or ENTER key after typing your username. 2. When the password prompt appears, type in your password. Your password is never displayed on the screen as a security measure. It also is case sensitive. Press the RETURN or ENTER key after entering your password. What happens after you successfully login depends upon your system: o Many UNIX systems will display a login banner or "message of the day". Make a habit of reading this since it may contain important information about the system. o Other UNIX systems will automatically configure your environment and open one or more windows for you to do work in. o You should see a prompt - usually a percent sign (%) or dollar sign ($). This is called the "shell prompt" (the shell is discussed in detail later). It indicates that the system is ready to accept commands from you. If your login attempt was unsuccessful, there are several possible reasons: 0. You made a typing error while entering your username or password 1. The CAPS LOCK key is on and everything is being sent to the system in uppercase letters.

2. You have an expired or invalid username or password, or the system security has changed. 3. There are system problems Example
login: kellyk kellyk's Password: ************************************************************ * Welcome to the Maui High Performance Computing Center ************************************************************ * * Aloha no! (Greetings) * * System maintenance is scheduled today from 2:00 * until 4:00 pm HST * * Mahalo nui loa (Thank you very much) * ************************************************************ %

Begin the "Logging On To The System" Exercise

Logging On To The System The details of logging in to a UNIX computer will differ from system to system. The steps covered here are specific for the MHPCC classroom.

2. 3. 4.



The instructor will assign every student a unique userid and password. Make sure you know yours before proceeding. The instructor will also show you how to setup your terminal for logging on. After your computer terminal is ready for logging on, review the screen and look for a place to type in your userid and password. Type in your userid, making sure that you distinguish between uppercase and lowercase letters as required. Press the return key when finished. Type in your password, also making sure that you distinguish between uppercase and lowercase letters as required. It will not appear as you type for security reasons. Press the return key when finished. If you are unsuccessful at logging in, the system will give you another try. Keep trying until you succeed. If you don't succeed after 5 tries, call the instructor. After you have successfully logged in, the system will automatically create your initial environment including a clock and a window for entering commands.

7. Notice the window - it should ask you which type of session you want. Answer the prompt by typing in the number which matches: Introduction to UNIX. You will then be prompted to "start Netscape" - type y for yes. 8. After a few seconds, you should see the Introduction to UNIX window. If you do not, call the instructor. 9. Return to the tutorial to learn about the next section before proceeding.

Using UNIX Commands This exercise will familiarize you with the basics of issuing UNIX commands.

You should still have a window on your screen from the previous exercise. Select that window by dragging the mouse pointer into the window and then clicking with the left mouse button. The window is now ready to accept input from you. 2. Try a few simple commands which require no arguments or options:
date whoami who w pwd clear show date and time show your userid show who is logged onto the system show who is logged onto the system print the working directory's name clear the screen

3. Now try some commands which require arguments and/or options:

ls -a ls -al cat .cshrc mkdir dir1 cd dir1 cd .. rmdir dir1 cp .login new.login wc new.login wc -l new.login rm new.login list all files in current directory long list of current directory display contents of .cshrc file make a directory called dir1 change directory to dir1 change to parent directory remove directory dir1 copy the .login file to new.login count the lines, words and characters in the new.login file - count just the lines - remove the new.login file

4. Try using multiple commands on one line. Don't forget to include the semicolon between commands.
cp .login testfile ; cat testfile - copy a file and then show its contents

ls -l testfile ; rm testfile ; ls -l testfile - list (long) a file, remove it, and then try to list it again

5. Return to the tutorial to learn about the next section before proceeding.

Special Characters This exercise will acquaint you with the use of several of the UNIX special characters.

First, make sure you are in your home directory (issue the "cd" command with no arguments). Now "cd" to this exercise's subdirectory by using the command:
cd GetStart

2. Using the "*" wildcard character, list all of the files in this subdirectory:
ls *

3. Using the "?" wildcard character, list all files with 3 character names:
ls ???

4. Using square brackets and wildcard characters, try listing files several different ways:
ls ls ls ls ls ls [a-c]* [abcde]* [a-z]* [z]* ??[c]* ?[e]*

5. Using the right angle bracket ">" and the semi-colon ";", concatenate three files into a single new file and then display it:
cat alpha beta gamma > newfile ; cat newfile

6. Return to the tutorial to learn about the next section before proceeding.

Terminal Control Keys This exercise will familiarize you with several of the terminal control keys used by UNIX.





Erasing the command line: At the command prompt, begin typing several characters. It doesn't matter what you type (but don't press the Return key) because you will then erase the line by typing CTRL-u. Killing a command: Start the command sleep 300 which simply "sleeps" for 300 seconds. After it is started, try using another UNIX command such as "ls". What happens? Kill the sleep process by using CTRLc, and try it again. What happens now? Backspacing: At the command prompt, begin typing several characters. It doesn't matter what you type (but don't press the Return key). After typing several characters, try using CRTL-h to backspace. Most keyboards will allow you to backspace by using a "backspace" or "delete" key also. Screen Scrolling: Issue a command which will send lots of information to the screen: ls -R / While the information is being displayed, use CTRLs to stop it and then CTRL-q to restart it. Try CTRL-s and CTRL-q a couple times. Then kill the process with CTRL-c. Return to the tutorial to learn about the next section before proceeding.

Changing Your Password This exercise will familiarize you with changing your password on a UNIX system.

2. 3.

4. 5.

Each student should have received an initial password from the instructor. If you are not sure of yours, ask the instructor. Think of a new password which follows the guidelines mentioned in the tutorial. Remember what it is. Change your initial password by issuing the passwd command. As your are prompted, supply your old password and then your new password. You will be asked to type the new password twice for confirmation. Notice that nothing appears on the screen as you type. Now change your password back to the original password. Please don't forget to do this step! Return to the tutorial to learn about the next section before proceeding.

Getting Information This exercise will familiarize you with several different UNIX utilities for obtaining information about the system.

Use the man command to read in depth about some common UNIX utilities:
man man man man ls cp rm man

2. Use the following commands to find out about users on the system, including yourself:
who whoami who am i finger finger your userid

3. Return to the tutorial to learn about the next section before proceeding.

Logging Off The System This exercise will familiarize you with logging off a UNIX system - in particular, an MHPCC training system. Note that this procedure may differ from system to system.

In your open window, type either of the following commands to logout:

logout exit

2. This will cause your window to disappear. In other UNIX systems, without a windows environment, these same commands would terminate your entire session. 3. This concludes the "Getting Started" Exercises. Return to the Getting Started tutorial or to the Table of Contents.

Your Home Directory

Each user has a unique "home" directory. Your home directory is that part of the file system reserved for your files. After login, you are "put" into your home directory automatically. This is where you start your work. You are in control of your home directory and the files which reside there. You are also in control of the file access permissions (discussed later) to the files in your home directory. Generally, you alone should be able to create/delete/modify files in your home directory. Others may have permission to read or execute your files as you determine. In most UNIX systems, you can "move around" or navigate to other parts of the file system outside of your home directory. This depends upon how the file permissions have been set by others and/or the System Administrator, however.

Using UNIX Commands

UNIX commands are executable files and built-in utility programs All UNIX commands are case sensitive. Most commands are in lower case. Commands typically have the syntax:
command option(s) argument(s)

Options 1. Modify the way that a command works 2. Usually consist of a hyphen followed by a single letter 3. Some commands accept multiple options which can usually be grouped together after a single hyphen 4. A small number of commands require each option to be given separately 5. Should be separated from the command name by a space Arguments 6. Most commands are used together with one or more arguments 7. Some commands assume a default argument if none is supplied 8. Arguments are optional for some commands and required by others

9. In most cases, multiple arguments should be separated from each other by a space. They should be separated from the command name and/or options by a space also. Examples 10. To use a command with no argument: the "date" command displays the current time and date.

11. To use a command with a single argument: the "cd" command changes to the directory of its argument, newdir
cd newdir

12. To use a command with both an option and an argument: the wc command counts the number of words, characters, and lines in a file. By using a different option you can choose what is counted.
wc -w file1 wc -c file1 wc -l file1 counts the words in file1 counts the characters in file1 counts the lines in file1

13. To use a command with several arguments: the cat command takes the names of three files as arguments. It prints file1 followed by file2 and then file3 on the screen.
cat file1 file2 file3

14. To use a command with multiple options and default argument: the ls command provides a long (l) listing of all (a) files and also shows the file size (s). Because no argument is specified, the default argument (current directory) will be used.
ls -als

Multiple commands can be entered on one line if you separate each with a semicolon. For example: this command line contains two commands. The first, cd newdir changes the current directory to the directory newdir. The second, ls -l produces a long listing of the contents of the newdir directory.
cd newdir ; ls -l

Commands can continue beyond one line by using a backslash (\) character. For example: this command copies the file called recipe from kelly's home

directory to the current directory and renames it kelly.recipe. It then sends this file to the printer ps3 with the request that 6 copies be printed.
cp /users/kelly/recipe kelly.recipe ; \ lpr -Pps3 #6m kelly.recipe

Begin the "Using UNIX Commands" Exercise

Special Characters

The UNIX shell interprets a number of characters in special ways. These characters are most often used with UNIX commands - as arguments and for other means. The following list contains most of UNIX's special characters
NEWLINE ; ( ) & | > >> < * ? \ ' " ` [ ] $ { } . # : initiates command execution separates commands on same line groups commands or identifies a function executes a command in the background pipe redirects standard output appends standard output redirects standard input wildcard for any number of characters in a file name wildcard for a single character in a file name quotes the following character quotes a string preventing all substitutions quotes a string allowing variable and command substitution performs command substitution denotes a character class in a file name references a variable command grouping within a function executes a command (if at beginning of line) begins a comment null command

Examples 1. Use the * character in file names to match any number of characters. The following command:
ls *.txt

Will match the following files:

chapter1.txt doc.txt memo.txt a.txt

Will not match the following files:

doctxt txt.memo

2. Use the ? character in file names to match any single character. The following command:
ls ???.txt

Will match the following files:

one.txt doc.txt two.txt

Will not match the following files:

chap1.txt doctxt

3. Use the [ ] characters in file names to match any character within a range of characters. The following command:
ls chapter[1-3].txt

Will match the following files:

chapter1.txt chapter2.txt chapter3.txt

Will not match the following files:

chap1.txt chapter4.txt

Other uses for special characters and examples will be discussed later. Begin the "Special Characters" Exercise

Terminal Control Keys

Several key combinations on your keyboard usually have a special effect on the terminal. These "control" (CTRL) keys are accomplished by holding the CTRL key while typing the second key. For example, CTRL-c means to hold the CTRL key while you type the letter "c". The most common control keys are listed below:
CTRL-u CTRL-c - erase everything you've typed on the command line - stop/kill a command


- backspace (usually) - suspend a command - stop the screen from scrolling - continue scrolling - exit from an interactive program (signals end of data)

Begin the "Terminal Control Keys" Exercise

Changing Your Password

Your password is important; it stops other users from gaining access to your account. Never give your password to anyone You should change your initial password very soon after your first login To change your password: enter the command passwd and then respond to the prompts by entering your old password followed by your new one. You are then asked to retype your password for confirmation. Note that what you type will not appear on the screen for security reasons. For example:
passwd Old password: - enter your current password New password: - enter your new password Retype new password: - re-enter your new password

If you make a mistake, the message: Mismatch - password unchanged. is displayed and your password remains unchanged. Try again.

Guidelines for creating a password Don't

o o o o

choose a word from a dictionary use personal information such as your name, make of car, pet, sweetheart, etc. tell anyone your passwd write your password down anywhere

keep the password you were given when you first got your userid

Do choose an obscure password preferably between 6 and 8 characters in length, of mixed case and containing at least one non-alphanumeric character such as ! or @ o change your password at regular intervals Keep in mind that there are people who think it's fun to "crack" passwords and get into other people's accounts. There are plenty of easily available "cracking" programs which make guessing easy passwords a cinch. Begin the "Changing Your Password" Exercise

Getting Information

The "man" command o The "man" command man gives you access to an on-line manual which potentially contains a complete description of every command available on the system. In practice, the manual usually contains a subset of all commands. o man can also provide you with one line descriptions of commands which match a specified keyword o The online manual is divided into sections:
Section ------1 2 3 4 5 6 7 8 l n Description ----------User Commands System Commands Subroutines Devices File Formats Games Miscellaneous System Administration Local Commands New Commands

Examples of using the man command: 1. To display the manual page for the cp (copy files) command:
man cp

--More--23% at the bottom left of the screen means that only 23% of the man page is displayed. Press the space bar to display more of it or type q to quit.

2. By default, the man page in section 1 is displayed if multiple sections exist. You can access a different section by specifying the section. For example:
man 8 telnetd

3. Keyword searching: use the -k option followed by the keyword. Two examples appear below.
man -k mail man -k 'copy files'

4. To view a one line description of what a command does:

whatis more

will display what the "more" command does: more, page (1) - browse or page through a text file

who - shows who is on the system

who who am i

finger - displays information about users, by name or login name

finger doe finger userid

Begin the "Getting Information" Exercise

Logging Off The System

To finish using a UNIX system you must go through a process known as "logging out" or "logging off". To logout enter the command logout or exit. If this does not, work press Ctrl-d. If you have a .logout file in your home directory, the system will execute any commands contained there.

Problems 1. If you see the message There are stopped jobs it is a warning which tells you that there is a job which you suspended earlier (Ctrl-z) or a job running in the background (discussed later). The simplest way to accomplish the logout is to just issue the logout command again. Your suspended/background jobs will be terminated and you will be logged off the system. 2. If you see the message Not login shell it means you are working in another "shell" that has been started from within your "login shell" (shells will be discussed later). To logout, issue the exit command and then try to logout again.

Begin the "Logging Off the System" Exercise

This concludes the tutorial. Return to the Table of Contents

Hierarchical File Structure

All of the files in the UNIX file system are organized into a multi-leveled hierarchy called a directory tree. A family tree is an example of a hierarchical structure that represents how the UNIX file system is organized. The UNIX file system might also be envisioned as an inverted tree or the root system of plant. At the very top of the file system is single directory called "root" which is represented by a / (slash). All other files are "descendents" of root. The number of levels is largely arbitrary, although most UNIX systems share some organizational similarities. The "standard" UNIX file system is discussed later.

/ (root) | --------------------| | | /bin /usr /tmp | | ------------------| | | /public /misc /staff | | -----------------------------| | | | | | /software /doc /john /mary /bill /carl

File Types
The UNIX filesystem contains several different types of files:

Ordinary Files o Used to store your information, such as some text you have written or an image you have drawn. This is the type of file that you usually work with. o Always located within/under a directory file o Do not contain other files Directories o Branching points in the hierarchical tree o Used to organize groups of files o May contain ordinary files, special files or other directories o Never contain "real" information which you would work with (such as text). Basically, just used for organizing files. o All files are descendants of the root directory, ( named / ) located at the top of the tree. Special Files o Used to represent a real physical device such as a printer, tape drive or terminal, used for Input/Ouput (I/O) operations o Unix considers any device attached to the system to be a file including your terminal: By default, a command treats your terminal as the standard input file (stdin) from which to read its input Your terminal is also treated as the standard output file (stdout) to which a command's output is sent Stdin and stdout will be discussed in more detail later o Two types of I/O: character and block o Usually only found under directories named /dev Pipes o UNIX allows you to link commands together using a pipe. The pipe acts a temporary file which only exists to hold data from one command until it is read by another o For example, to pipe the output from one command into another command:
who | wc -l

This command will tell you how many users are currently logged into the system. The standard output from the who command is a list of all the users currently logged into the system. This output is piped into the wc command as its standard input. Used with the -l option this command counts the numbers of lines in the standard input and displays the result on its standard output - your terminal.

File Names

UNIX permits file names to use most characters, but avoid spaces, tabs and characters that have a special meaning to the shell, such as:
& ; ( ) | ? \ ' " ` [ ] { } < > $ - ! /

Case Sensitivity: uppercase and lowercase are not the same! These are three different files:
NOVEMBER November november

Length: can be up to 256 characters Extensions: may be used to identify types of files
libc.a program.c alpha2.f xwd2ps.o mygames.Z archive, library file C language source file Fortran source file Object/executable code Compressed file

Hidden Files: have names that begin with a dot (.) For example:
.cshrc .login .mailrc .mwmrc

Uniqueness: as children in a family, no two files with the same parent directory can have the same name. Files located in separate directories can have identical names. Reserved Filenames:
/ . .. ~ the root directory (slash) current directory (period) parent directory (double period) your home directory (tilde)


Specify where a file is located in the hierarchically organized file system Must know how to use pathnames to navigate the UNIX file system

Absolute Pathname: tells how to reach a file begining from the root; always begins with / (slash). For example:

Relative Pathname: tells how to reach a file from the directory you are currently in ( current or working directory); never begins with / (slash). For example:
training/sample.f ../bin ~/projects/report.001

For example, if your current directory is /usr/home/johnson and you wanted to change to the directory /usr/home/quattro, you could use either of these commands:
cd ../quattro cd /usr/home/quattro - relative pathname - absolute pathname

File and Directory Commands

UNIX provides a number of commands for working with files. The more common ones are described in this section. Note that these commands usually have several options and accept wildcard characters as arguments. For details, see the respective man pages which are hyperlinked to each command name. ls - lists files
ls ls ls ls ls ls show contents of working directory list file, if it exists in working directory show contents of the directory dir shows all your files, including hidden ones give detailed listing of contents mark directories with "/" and executable files with "*" - show all files with suffix ".doc"

file dir -a -al -F

ls *.doc

more - browses/displays files one screen at a time. Use h for help, spacebar to page, b for back, q to quit, /string to search for string

more sample.f

pg - browses/displays files one screen at a time. Similar to the more utility in function but has different commands and options. See the man page for details.
pg sample.f

less - similar to more, but with more features. Not available on every system.
less sample.f

head - displays the first n lines of a file

head sample.f head -5 sample.f head -25 sample.f - display first 10 lines (default) - display first 5 lines - display first 25 lines

tail - displays the last n lines or n characters of a file

less less less less sample.f -5 sample.f -5c sample.f -25 sample.f display display display display last last last last 10 lines (default) 5 lines 5 characters 25 lines

cat - dumps the entire file to the screen without paging. This command is more useful for concatenating (hence the name "cat") files together than it is for reading files.
cat myprog.c cat -b myprog.c cat file1 file2 > file3 - diplays entire file - shows line numbers - adds file1 and file2 to make file3

cp - copies files. Will overwrite unless otherwise specified. Must also have write permission in the destination directory.
cp sample.f sample2.f cp -R dir1 dir2 cp -i file.1 - copies sample.f to sample2.f - copies contents of directory dir1 to dir2 - prompts if will be overwritten - copies all files with .txt

cp *.txt chapt1

cp /usr/doc/README cp ~betty/index . ~

suffix to directory chapt1 - copies file to your home directory - copies the file "index" from user betty's home directory to current directory

mv - moves files. Will overwrite unless otherwise specified. Must also have write permission in the destination directory.
mv sample.f sample2.f mv dir1 newdir/dir2 mv -i file.1 - moves sample.f to sample2.f - moves contents of directory dir1 to newdir/dir2 - prompts if will be overwritten - moves all files with .txt suffix to directory chapt1

mv *.txt chapt1

rm - deletes/removes files or directories if file permissions permit.

rm rm sample.f chap?.txt - deletes sample.f - deletes all files with chap as the first four characters of their name and with .txt as the last four characters of their name - deletes all files in current directory but asks first for each file - recursively removes all files in the directory olddir, including the directory itself

rm -i * rm -r /olddir

Begin the Filesystem exercises - Part 1.

file - identifies the "type" of file. The command syntax is:

file filename

For example:
file * - reports all files in current directory and their types. The output might appear as shown below: ascii text


bin: bggen: bmbinc: machines.sp1: man2html: man2html.c:

directory English text executable or object module not stripped commands text [nt]roff, tbl, or eqn input text executable or object module not stripped ascii text

find - finds files. The syntax of this command is:

find pathname -name filename -print

The pathname defines the directory to start from. Each subdirectory of this directory will be searched. The -print option must be used to display results. You can define the filename using wildcards. If these are used, the filename must be placed in 'quotes'.
find . -name mtg_jan92 -print - looks for the file mtg_jan92 in current directory find ~/ -name README -print - looks for files called README throughout your home directory find . -name '*.fm' -print - looks for all files with .fm suffix in current directory find /usr/local -name gnu -type d -print - looks for a directory called gnu within the /usr/local directory

diff - comparing two files or directories. Indicates which lines need be added (a), deleted (d) or changed (c). Lines in file1 are identified with a (<) symbol: lines in file2 with a (>) symbol
diff file1 file2 diff -iw file1 file2 diff dir1 dir2 - compares file1 to file2 - compares two files ignoring letter case and spaces - compares two directories showing files which are unique to each and also, line by line differences between any files in common.

For example, if file1 and file2 are:

John erpl08@ed Joe Kim Keith keith@festival

John erpl08@ed Joe Jean Jim jim@frolix8 Kim Keith keith@festival

Using the diff command: diff file1 file2 Yields the output:
2a3,4 > Jean > Jim jim@frolix8

Which means that to make these files match you need to add (a) lines 3 and 4 (3,4) of file2 (>) after line 2 in file1. sdiff - similar to diff, but displays each line of the two files side by side, making it easier for you to see the differences between them Lines that are different are shown with a | symbol. Lines unique to file1 are identified by a < symbol; lines unique to file2 with a > symbol. Identical lines appear next to each other. The option -w 80 is used to set the width of the output from the command to 80 characters. The default is 130 characters.
sdiff -w 80 file1 file2 Mike erpl08@ed Joe Kim Sam s.wally@aston Keith keith@festival

| John erpl08@ed Joe > Jean > Jim jim@frolix8 Kim < Keith keith@festival

ln - link one file name to another. The command syntax is:

ln source linkname

Making a link to a file or directory does not create another copy of it. It simply makes a connection between the source and the linkname. Allows a single file to be "pointed to" by other filenames without having to duplicate the file.
ln results.1 - links filename "" to


notes ../Notes.jan

the real file results.1 in the current directory. - links filename "notes" in current directory to real file Notes.jan in parent directory.

sort - sorts files, merges files that are already sorted, and checks files to determine if they have been sorted. The command syntax is:
sort options filename

By default, lines in "filename" are sorted and displayed to the screen. If the "filename" parameter specifies more than one file, the sort command concatenates the files and sorts them as one file. An output file can be specified with the -o flag. Files can be sorted by "fields" - single or multiple. The sort command supports many options. See the man page for details.
sort addresses - sorts the file addresses and displays output on screen sort -o sorted addresses - sorts the file addresses and writes output to the file called sorted. sort -u -o mail_labels addresses - removes all duplicate lines from the file addresses and writes the output in the file mail_labels. sort +2 -4 addresses - sorts the file by its third and fourth fields. Note that +2 means to skip first two fields and -4 means to stop after the fourth field.

Continue the Filesystem exercises - Part 2. pwd - print working directory. Tells you which directory you are currently in.

mkdir - make directory. Will create the new directory in your working directory by default.
mkdir mkdir /u/training/data data2

cd - change to specified directory. May specify either the absolute or relative pathname. cd with no pathname changes to your home directory.
cd cd cd cd cd cd /usr/local doc/training .. ~/data ~joe - change to /usr/local - change to doc/training in current directory - change to parent directory - change to data directory in home directory - change to user joe's home directory - change to home directory

rmdir - remove directory. Directories must be empty before you remove them.
rmdir project1

To recursively remove nested directories, use the rm command with the -r option:
rm -r dirctory_name

Continue the Filesystem exercises - Part 3. A summary of commands and utilities related to the UNIX file system appears below. See the corresponding man pages for detailed information.
awk cat cd chgrp chmod chown comm cp df diff du file find fsck -search for and process patterns in a file, -display, or join, files -change working directory -change the group that is associated with a file -change the access mode of a file -change the owner of a file -compare sorted files -copy files -display the amount of available disk space -display the differences between two files -display information on disk usage -display file classification -find files -check and repair a file system

grep head ln lp lpr ls mkdir more mv od pg pr pwd rm rmdir sed sort spell tail tar umask uniq wc whatis whereis which

-search for a pattern in files -display the first few lines of a file -create a link to a file -print files (System V) -print files (Berkeley) -list information about files -create a directory -display a file one screen at a time (System V) -move and/or rename a file -dump a file -display a file one screen at a time (Berkeley) -paginate a file -print the working directory -remove (delete) files -remove (delete) a directory -stream editor (non-interactive) -sort and/or merge files -check a file for spelling errors -display the last few lines of a file -store or retrieve files from an archive file -set file creation permissions -display the lines in a file that are unique -counts lines, words and characters in a file -list man page entries for a command -show where executable is located in path -locate an executable program using "path"

Access Permissions
UNIX is a multi-user system. Every file and directory in your account can be protected from or made accessible to other users by changing its access permissions. Every user has responsibility for controlling access to their files. Permissions for a file or directory may be any or all of:
r w x read write execute = running a program

Each permission (rwx) can be controlled at three levels:

u g o user = yourself group = can be people in the same project other = everyone on the system

File access permissions are displayed using the ls -l command. The output from the ls -l command shows all permissions for all levels as three groups of three according to the scheme:

owner read (r) owner write (w) owner execute (x) group read (r) group write (w) group execute (x) public read (r) public write (w) public execute (x) which are displayed as: -rwxrwxrwx

Example outputs from the ls -l command:

-rw------- 2 smith staff 3287 Apr 8 12:10 file1 User has read and write permission. Group and others have no permissions. -rw-r--r-- 2 smith staff 13297 Apr 8 12:11 file2 User has read and write permission. Group and others can only read the file. -rwxr-xr-x 2 smith staff 4133 Apr 8 12:10 myprog User has read, write and execute permission. Group and others can read and execute the file. drwxr-x--- 2 smith staff 1024 Jun 17 10:00 SCCS This is a directory. The user has read, write and execute permission. Group has read and execute permission on the directory. Nobody else can access it.

Note: a directory must have both r and x permissions if the files it contains are to be accessed. The chmod command is used to change access permissions for files which you own. The syntax is:
chmod permission_triads [who][action][permissions] filename

who u g o a = = = = user group other all action + = add - = remove permissions r = read w = write x = execute

chmod a+r sample.f - Adds read permission for all users to the file sample.f. chmod o-r sample.f - Removes read permission for others to the file sample.f. chmod og+rx prog* - Adds read and execute permissions for group and others to all files which contain "prog" as the first four characters of their name. chmod +w * - Adds write permission for user to all files in current directory.

File access permissions can also be changed by a numerical (octal) chmod specification. Read permission is given the value 4, write permission the value 2 and execute permission 1.
r 4 w 2 x 1

These values are added together for any one user category:
0 1 2 3 4 5 6 7 = = = = = = = = no permissions execute only write only write and execute (1+2) read only read and execute (4+1) read and write (4+2) read and write and execute (4+2+1)

So access permissions can be expressed as three digits. For example:

user chmod 640 file1 chmod 754 file1 chmod 664 file1 rwrwx rwgroup r-r-x rwothers --r-r--

Never set write permission for all other users on a file or directory which is in your home directory. If you do other users will be able to change its content. This can represent a serious security risk.

The umask command is used to set your default file permissions. Typically, the umask command is included as part of your .profile, .cshrc or .login file. The umask command accepts only octal specifications. Note that these are different than those used by the chmod command, and in fact, represent which permissions to "mask out", or remove.
Octal number 0 1 2 3 4 5 6 7 Access permissions given rwx read, write and execute rwread and write r-x read and execute r-read only -wx write and execute -wwrite only --x execute only --no permissions

Example umask commands:

umask 077 - Subtracts 077 from the system defaults for files (666) and directories (777). Results in default access permissions for your files of 600 (rw-------) and for directories of 700 (rwx------). umask 002 - Subtracts 002 from the sytem defaults to give a default access permission for your files of 664 (rw-rw-r--) and for your directories of 775 (rwxrwxr-x). umask 022 - Subtracts 022 from the system defaults to give a default access permission for your files of 644 (rw-r--r--) and for your directories of 755 (rwxr-xr-x).

Begin the Access Permissions Exercise

Standard UNIX File System

There is no single standard UNIX file structure. Most UNIX systems however, follow a general convention for filesystem organization at the highest level.
/(root) - The top level directory referred to as root.

Contains all files in the file system. /bin /dev /etc - Executable files for standard UNIX utilities - Files that represent input/output devices - Miscellaneous and system administrative files such as the password file and system start up files. - UNIX program libraries - Temporary space that can be used by programs or users. - More UNIX utilities. By convention /bin contains standard utilities and /usr/bin contains less common utilities.

/lib /tmp /usr/bin

/usr/bin/X11 - X windows binaries /usr/lib - More UNIX libraries

/usr/lib/X11 - X windows libraries /usr/local /usr/ucb /u /var - Programs installed by local site - Berkeley utilities - User home directories - Variable sized files - can grow and shrink dynamically, such a users mail spool and print spool files.

Begin the Standard UNIX Filesystem Exercises

This concludes the tutorial. Return to the Table of Contents