![Page 1: Introduction to UNIX CS208. What is UNIX? UNIX is an Operating System (OS). An operating system is a control program that allocates the computer's resources,](https://reader036.vdocuments.mx/reader036/viewer/2022062304/56649d4d5503460f94a2bb1f/html5/thumbnails/1.jpg)
Introduction to UNIX
CS208
![Page 2: Introduction to UNIX CS208. What is UNIX? UNIX is an Operating System (OS). An operating system is a control program that allocates the computer's resources,](https://reader036.vdocuments.mx/reader036/viewer/2022062304/56649d4d5503460f94a2bb1f/html5/thumbnails/2.jpg)
What is UNIX?
• UNIX is an Operating System (OS).
• An operating system is a control program that allocates the computer's resources, schedules tasks, and helps the user communicate with the computer.
• Most popular PC operating systems: Windows 95/98/2000/XP -- proprietary, single-user OS
• UNIX was developed long before Windows, about 30 years ago at AT&T Bell Labs (95% written in “C” programming language).
![Page 3: Introduction to UNIX CS208. What is UNIX? UNIX is an Operating System (OS). An operating system is a control program that allocates the computer's resources,](https://reader036.vdocuments.mx/reader036/viewer/2022062304/56649d4d5503460f94a2bb1f/html5/thumbnails/3.jpg)
UNIX Compared with other OS• Mature and stable OS
• Large user community
• Vendor-independent OS
• Network-portable window system (X)
• Runs on range of hardware (PC - Cray)
• Common Open System Environment (COSE)– Source code is available to view and modify
![Page 4: Introduction to UNIX CS208. What is UNIX? UNIX is an Operating System (OS). An operating system is a control program that allocates the computer's resources,](https://reader036.vdocuments.mx/reader036/viewer/2022062304/56649d4d5503460f94a2bb1f/html5/thumbnails/4.jpg)
Multi-user, Multi-tasking• More than one user can run at the same time and each
user can run more than one task at the same time
• In Unix, each program is started as a process.
– A process is a program in execution.
• Usually only one copy of a program, but there may be many processes running the same program.
• Each interactive user may have:
– only one process in foreground
– may have several processes in background
![Page 5: Introduction to UNIX CS208. What is UNIX? UNIX is an Operating System (OS). An operating system is a control program that allocates the computer's resources,](https://reader036.vdocuments.mx/reader036/viewer/2022062304/56649d4d5503460f94a2bb1f/html5/thumbnails/5.jpg)
Most Important Feature of UNIX
• Most important feature of UNIX: STABILITY– 30 years to get the bugs out– Important in shared environments and critical
applications
• Shared Environments Example: University– Windows NT crashes at least once a day in labs– UNIX servers crash about once a semester
(usually due to hard disk failure)– UNIX more than 100 times more reliable than
Windows!
![Page 6: Introduction to UNIX CS208. What is UNIX? UNIX is an Operating System (OS). An operating system is a control program that allocates the computer's resources,](https://reader036.vdocuments.mx/reader036/viewer/2022062304/56649d4d5503460f94a2bb1f/html5/thumbnails/6.jpg)
UNIX Versions • Two main types of UNIX:
– BSD (Berkeley Software Distribution)/OSF– System V (developed at AT&T)
• Different versions of UNIX for different hardware:– Sun Microsystem’s Solaris (and SunOS)– Hewlett-Packard’s HP-UX– IBM’s AIX– SGI’s IRIX
![Page 7: Introduction to UNIX CS208. What is UNIX? UNIX is an Operating System (OS). An operating system is a control program that allocates the computer's resources,](https://reader036.vdocuments.mx/reader036/viewer/2022062304/56649d4d5503460f94a2bb1f/html5/thumbnails/7.jpg)
Unix Operating System Structure• OS mediates between the user and the
computer User
Application Programs
Kernel
Hardware
Shell
![Page 8: Introduction to UNIX CS208. What is UNIX? UNIX is an Operating System (OS). An operating system is a control program that allocates the computer's resources,](https://reader036.vdocuments.mx/reader036/viewer/2022062304/56649d4d5503460f94a2bb1f/html5/thumbnails/8.jpg)
Why has Unix been successful?• UNIX is portable, because it was written in C.
– Provides hardware independence.
• Open System
– Underlying operating system source code is available
• Provides a productive environment
– Allows multi-tasking and sharing of data
– Excellent C development environment is built-in
– Networking capabilities are built in
![Page 9: Introduction to UNIX CS208. What is UNIX? UNIX is an Operating System (OS). An operating system is a control program that allocates the computer's resources,](https://reader036.vdocuments.mx/reader036/viewer/2022062304/56649d4d5503460f94a2bb1f/html5/thumbnails/9.jpg)
Unix Disadvantages UNIX is not as user-friendly as some operating
systems– Command names are often cryptic– User help is not great
UNIX does not error check user commands to protect users from hurting themselves or the system– Example: Request to copy a file over an existing
file will overwrite the existing file with no warning.
![Page 10: Introduction to UNIX CS208. What is UNIX? UNIX is an Operating System (OS). An operating system is a control program that allocates the computer's resources,](https://reader036.vdocuments.mx/reader036/viewer/2022062304/56649d4d5503460f94a2bb1f/html5/thumbnails/10.jpg)
Unix Disadvantages
UNIX is less secure than some operating systems– Developed to be used as a software development
environment, in which all users are working together cooperatively. Security was traded for more convenience and flexibility.
– Well-documented open code makes hacking easier.
UNIX's portability also makes it less efficient on any particular hardware.– Proprietary operating systems are optimized for that
hardware.
![Page 11: Introduction to UNIX CS208. What is UNIX? UNIX is an Operating System (OS). An operating system is a control program that allocates the computer's resources,](https://reader036.vdocuments.mx/reader036/viewer/2022062304/56649d4d5503460f94a2bb1f/html5/thumbnails/11.jpg)
Basic UNIX Commands
![Page 12: Introduction to UNIX CS208. What is UNIX? UNIX is an Operating System (OS). An operating system is a control program that allocates the computer's resources,](https://reader036.vdocuments.mx/reader036/viewer/2022062304/56649d4d5503460f94a2bb1f/html5/thumbnails/12.jpg)
The Unix PromptThe Unix Prompt
• After you log in, and the startup files have been run, the shell will display a prompt$
• Different shells and different systems have different prompts.
– Two common prompts are $ and #.
– Your prompt can be changed.
• A prompt (plus a cursor) tells you that the system is ready for your commands.
![Page 13: Introduction to UNIX CS208. What is UNIX? UNIX is an Operating System (OS). An operating system is a control program that allocates the computer's resources,](https://reader036.vdocuments.mx/reader036/viewer/2022062304/56649d4d5503460f94a2bb1f/html5/thumbnails/13.jpg)
Standard Command Format
Format: command [options] <arguments>• stuff in brackets is optional• boldface words are literals (must be typed as is)• <> enclosed words are args (replace appropriately)
• Commands are case sensitive (mostly lowercase)
• Spaces must be inserted between commands, options, arguments
![Page 14: Introduction to UNIX CS208. What is UNIX? UNIX is an Operating System (OS). An operating system is a control program that allocates the computer's resources,](https://reader036.vdocuments.mx/reader036/viewer/2022062304/56649d4d5503460f94a2bb1f/html5/thumbnails/14.jpg)
Standard Command Format• Options (also called flags) modify how the
command works (command behavior)– single letters prefixed with a dash “-”– combined or separated (e.g., -al = -a -l)– come before arguments
• Arguments define the command scope– Optional for some commands, mandatory for others– Some commands assume a default argument if none is
supplied – Usually files or directories
![Page 15: Introduction to UNIX CS208. What is UNIX? UNIX is an Operating System (OS). An operating system is a control program that allocates the computer's resources,](https://reader036.vdocuments.mx/reader036/viewer/2022062304/56649d4d5503460f94a2bb1f/html5/thumbnails/15.jpg)
Basic Commands
date - Print the date and time
$ date
Wed Feb 3 12:13:07 MDT 2003
$
echo - Display command line input to screen
$ echo Hi, I am your instructor!
Hi, I am your instructor!
$
![Page 16: Introduction to UNIX CS208. What is UNIX? UNIX is an Operating System (OS). An operating system is a control program that allocates the computer's resources,](https://reader036.vdocuments.mx/reader036/viewer/2022062304/56649d4d5503460f94a2bb1f/html5/thumbnails/16.jpg)
Commands to Manipulate Files
• ls lists files in a directory (names, not the contents of files)
• cat, head, tail, more display files
• rm removes files (and directories)
• cp copies files (and directories)
• mv moves (renames) files (and directories)
![Page 17: Introduction to UNIX CS208. What is UNIX? UNIX is an Operating System (OS). An operating system is a control program that allocates the computer's resources,](https://reader036.vdocuments.mx/reader036/viewer/2022062304/56649d4d5503460f94a2bb1f/html5/thumbnails/17.jpg)
List Files in a DirectoryFormat: ls [-alRF…] <file-list>
-a list all files including the dot files
-l long format (show file type, permissions, #links, owner, etc)
-R recursive list subdirectories
-F list directories with file type(trailing / *)
![Page 18: Introduction to UNIX CS208. What is UNIX? UNIX is an Operating System (OS). An operating system is a control program that allocates the computer's resources,](https://reader036.vdocuments.mx/reader036/viewer/2022062304/56649d4d5503460f94a2bb1f/html5/thumbnails/18.jpg)
Listing Files in a DirectoryListing Files in a Directory
1 drwxr-xr-x 180 root admin 512 Oct 1 ../1 drwxr-xr-x 180 root admin 512 Oct 1 ../
2 -rw-r--r-- 1 smith fac 1314 Oct 3 file2 -rw-r--r-- 1 smith fac 1314 Oct 3 file
BLOCKSIZE
PERMISSIONSFILETYPE
# DIRECTORIES
OWNER
GROUP FILE SIZE
MODIFY DATE FILE
NAME
![Page 19: Introduction to UNIX CS208. What is UNIX? UNIX is an Operating System (OS). An operating system is a control program that allocates the computer's resources,](https://reader036.vdocuments.mx/reader036/viewer/2022062304/56649d4d5503460f94a2bb1f/html5/thumbnails/19.jpg)
Getting HelpGetting Help• Check the manual pages!
– For shell command, system programs, and library functions.
• Format: man <command>man –k <keywords>
• Man(ual) page formatNameSynopsisDescription (options, defaults, detail desc., examples)FilesSee AlsoBugs
![Page 20: Introduction to UNIX CS208. What is UNIX? UNIX is an Operating System (OS). An operating system is a control program that allocates the computer's resources,](https://reader036.vdocuments.mx/reader036/viewer/2022062304/56649d4d5503460f94a2bb1f/html5/thumbnails/20.jpg)
man Examples
$ man man
Displays help on the man command
$ man who
Displays help on the who command
$ man -k mail
Checks all man pages for keyword “mail”
![Page 21: Introduction to UNIX CS208. What is UNIX? UNIX is an Operating System (OS). An operating system is a control program that allocates the computer's resources,](https://reader036.vdocuments.mx/reader036/viewer/2022062304/56649d4d5503460f94a2bb1f/html5/thumbnails/21.jpg)
man Output Example$ man lsReformatting page. Wait... done
User Commands ls(1)
NAME ls - list contents of directory
SYNOPSIS /usr/bin/ls [ -aAbcCdfFgilLmnopqrRstux1 ] [ file... ] /usr/xpg4/bin/ls [ -aAbcCdfFgilLmnopqrRstux1 ] [ file... ]
--More--(11%)
spacebar - move forward one pageb – move back one pageh – more commands q – quit
![Page 22: Introduction to UNIX CS208. What is UNIX? UNIX is an Operating System (OS). An operating system is a control program that allocates the computer's resources,](https://reader036.vdocuments.mx/reader036/viewer/2022062304/56649d4d5503460f94a2bb1f/html5/thumbnails/22.jpg)
Viewing FilesViewing Files
cat concatonate and print to screen (ctrl-s and ctrl-q to stop/start)
head display first x lines of file
tail display last x lines of file
(both default to 10 lines)
more display part of file to screen
![Page 23: Introduction to UNIX CS208. What is UNIX? UNIX is an Operating System (OS). An operating system is a control program that allocates the computer's resources,](https://reader036.vdocuments.mx/reader036/viewer/2022062304/56649d4d5503460f94a2bb1f/html5/thumbnails/23.jpg)
Example: cat, head, tail
$ cat letter
Mr. Jones,
It is getting late. Please order some pizza and stop
by my office. We’ll tidy up a few more things before
calling it a night.
Thanks!
Ben
$ head –2 letter
Mr. Jones,
It is getting late. Please order some pizza and stop
$ tail –1 letter
Ben
![Page 24: Introduction to UNIX CS208. What is UNIX? UNIX is an Operating System (OS). An operating system is a control program that allocates the computer's resources,](https://reader036.vdocuments.mx/reader036/viewer/2022062304/56649d4d5503460f94a2bb1f/html5/thumbnails/24.jpg)
Copying FilesFormat:
cp [-ir…] file1 file2
cp [-ir…] file-list directory
cp [-ir…] directory directory
– i for interactive. Prompt whenever a file will be overwritten.
– r for recursive. copy a whole directory tree.
![Page 25: Introduction to UNIX CS208. What is UNIX? UNIX is an Operating System (OS). An operating system is a control program that allocates the computer's resources,](https://reader036.vdocuments.mx/reader036/viewer/2022062304/56649d4d5503460f94a2bb1f/html5/thumbnails/25.jpg)
cp Examples
$ lsletter1 secret$ cp letter1 letter2$ ls -Fletter1 letter2 secret/$ cp letter1 letter2 secret$ ls secretletter1 letter2
![Page 26: Introduction to UNIX CS208. What is UNIX? UNIX is an Operating System (OS). An operating system is a control program that allocates the computer's resources,](https://reader036.vdocuments.mx/reader036/viewer/2022062304/56649d4d5503460f94a2bb1f/html5/thumbnails/26.jpg)
Moving /Renaming FilesFormat:
mv [-i…] file1 file2
- Renames file1 to file2
mv [-i…] file-list directory
- Moves files from current location to new directory
mv [-i…] directory directory
- Renames a directory
![Page 27: Introduction to UNIX CS208. What is UNIX? UNIX is an Operating System (OS). An operating system is a control program that allocates the computer's resources,](https://reader036.vdocuments.mx/reader036/viewer/2022062304/56649d4d5503460f94a2bb1f/html5/thumbnails/27.jpg)
mv Examples
$ ls
letter memo saved
$ mv memo memo1
$ ls -F
letter memo1 saved/
$ mv saved trash
$ ls -F
letter memo1 trash/
![Page 28: Introduction to UNIX CS208. What is UNIX? UNIX is an Operating System (OS). An operating system is a control program that allocates the computer's resources,](https://reader036.vdocuments.mx/reader036/viewer/2022062304/56649d4d5503460f94a2bb1f/html5/thumbnails/28.jpg)
Deleting FilesFormat:
rm file-list
- Deletes files
rm -r directory
- Deletes directory and all files and directories within it
- Use with CAUTION!
![Page 29: Introduction to UNIX CS208. What is UNIX? UNIX is an Operating System (OS). An operating system is a control program that allocates the computer's resources,](https://reader036.vdocuments.mx/reader036/viewer/2022062304/56649d4d5503460f94a2bb1f/html5/thumbnails/29.jpg)
rm Examples
$ ls -F
letter1 letter2 secret/
$ rm letter1
$ ls -F
letter2 secret/
$ ls –F secret
memo morestuff/
$ rm –r secret
$ ls
letter2