You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
resources include CPU, memory, disk, tape, printers, terminals, modems, etc.
only one user allowed at a time for each resource
keeps track of filenames and directory structure
multi-tasking (one task at a time per processor actually executing)
multi-processing (schedules multiple processors)
multi-user
History of UNIX
developed at Bell Labs (AT&T) in 1969
unlike most OS's at the time, UNIX was multi-user, interactive, and simplified sharing of data & programs
became popular in industry as college and university graduates were trained in it
open system, ported to many different hardware platforms (unlike IBM, Burroughs, Univac mainframes)
software written for one UNIX system will often run on other systems with little or no modification
still very weak in areas of system management - tape management, security, hardware accounting, capacity planning tools, performance management including prioritization of jobs
hardware manufacturers modified UNIX to run on their systems and added enhancements
standardization was begun in response to Windows NT threat
System V Release 4 is one of the steps to address standardization
SVR4 includes many of the modifications that were being done by hardware manufacturers, if they were universally useful and applicable
History of Linux
GNU (Gnu's not Unix) was started in early 80's to create and promote free software
Linux was created by Linus Torvalds in the 1990's, released to the Internet in 1994, mostly using GNU C compiler
about 1/3 of Linux is GNU code from the Free Software Foundation - a Linux distribution consists of Linux kernel + GNU compilers/tools/utilities + other free software
Linux uses the Open Source model for development - code is placed on the Internet, users download and test it, programmers improve it and place it back on the web
there is competition among programmers to fix bugs and improve Linux
UNIX Structure
Hardware, surrounded by
UNIX Kernel (basic OS), surrounded by
Shell (user interface, command interpreter, and some built-in commands), surrounded by
Utilities (or commands)
most common shells: Bourne shell (sh), C shell (csh), Korn shell (ksh), Bourne again shell (bash), TC shell (tcsh), Z shell (zsh)
we'll mostly be concerned with the Bash shell, which is the most popular Linux shell
the Korn shell is the most popular Unix shell, and is very similar to the Bash shell
Entering Commands, Logging In & Out
to login, use an ssh (or similar) program, and provide userid and password
to backspace (erase), usually backspace, control-h, or control-backspace
to interrupt a process, usually control-c
to logout, use exit, logout, or control-d
use passwd to change password
command line arguments can be separated by one or more spaces or tabs
Some Commands
pwd will show your current directory
cd is used to change current directory, eg. cd directory-name
ls - lists information about files and directories
ls -a - all files (including hidden)
ls -l - long form, gives more information about files
ls -d - gives information about the directory itself, not contained files
these options can be mixed and matched, eg. ls -ld
cal - displays a calendar of the current month
cal 1995 - displays calendar for specified year
cal 3 1995 - displays calendar for specified month of specified year
date - gives date and time
who, w - information about users logged on to system
head -7 filename - displays first 7 lines, 10 is default
tail -11 filename - displays last 11 lines, 10 is default
cut is used to extract fields and characters from records
cut -f2 filename - extract 2nd field from all records in file1, using tab as delimiter (default)
cut -d' ' -f2,5 filename - extract 2nd and 5th field, using space as delimiter
cut -d' ' -f1-3,5 filename - extract 1st through 3rd and 5th fields, using space as delimiter
cut -c3-5 filename - extract 3rd to 5th characters
sort filename - displays records in ascending order
by default uses dictionary (ascii sort) order, from first to last character in each record
sort -f filename - sort ignoring case (fold to uppercase)
sort -k 3 filename - sort on 3rd field (default field delimiter is space)
sort -t: -k 3 filename - sort on 3rd field using colon as field delimiter
sort -rk 3 filename - sort on 3rd field in reverse (descending) order
sort -nk 5 filename - sort numerically on 5th field
sort -u filename - sort records, drop duplicate records
tr is used to translate characters to different characters
tr a A < filename - translate all characters "a" to "A"
tr "[a-z]" "[A-Z]" < filename - translate lowercase "a" through "z" to uppercase
tr ':' ' ' < filename - translate all colons to spaces
tr ' ' '\n' < filename - translate all spaces to newline characters
tr -d '\n' < filename - delete all newline characters
wc filename - displays various counts of the contents of a file
wc -l filename - displays number of lines in file
wc -c filename - displays number of characters in file
wc -w filename - displays number of words in file
grep 'string' filename - displays lines in file that contain the string
grep will be revisited in the lecture about regular expressions
Redirection
Standard Input, Output, and Error
standard input, output, and error for commands are sent to your terminal, unless they are redirected
cat - (by itself) will take input from terminal (use control-d to end input), send output and error messages to terminal
will redirect standard output to a file, deleting any existing contents of the file
cat > temp - will redirect output to a file called temp (this technique is sometimes called an "on the fly" document)
will redirect standard output to a file, but will append (add to) the end of the file
cat temp >> temp2 will append the contents of temp to the contents of temp2
2> will redirect standard error to a file (note that > is the same as 1>)
2>> will append standard error to a file
&2 (or 1>&2) will redirect standard output to standard error
/dev/null can be used to get rid of unwanted output
find / -name *.tmp 2>/dev/null
< will redirect standard input from a file, as in previous examples of tr
Piping
| (pipe) will connect the standard output of the command to its left, to the standard input of the command to its right
ls -al | more
ls -al | grep "temp" | sort -rnk5
tee will take standard input from a pipe, and send it as output to one or more files and to its standard output
ls -al | tee file1 file2
Multiple Commands
besides piping, there are other ways that multiple commands may be placed in one line
commands may be separated by semi-colons
each command will be executed when the previous command has terminated
for example: sleep 5; ls
commands may be grouped by using parentheses
(echo "Who is on:"; w) > whoson
commands may also be split over multiple lines, making it easier (for humans) to interpret a long command
quote or "escape" the newline character at the end of a line, to get rid of the special meaning of newline (to end a command line)
for example:
echo "This will be split over multiple
lines. Note that the shell will realize
that a pipe requires another command, so
it will automatically go to the next line" |
tr '[a-z]' '[A-Z]'