cmds-3

advertisement
Why UNIX?

In the 1980s, UNIX became popular



Customer demand for open systems:
 Application portability
 Vendor independence
 User portability
Time to market considerations
Major vendors (such as Sun, DEC, HP, IBM)
implemented UNIX based product lines.
Brief History

UNIX




Linux



Created at Bell Labs, 1969
BSD during mid 70s
AT&T began offering System II in early 80s
defined in 1991
Red Hat, 1995
http://www.computerhope.com/history/unix.htm
UNIX Philosophy





Simplicity
Reusability
Filters
Open Formats
Flexibility
What is the shell?
Utility program loaded when a user logs in
startup
init
getty
sh (bash)
login
Shell’s Responsibilities
interpreted
programming
languages
Program
Execution
variable and
filename
substitution
Shell
I/O
Redirection
environment
control
pipeline
hookup
Shell Substitutions

Certain characters are interpreted by the
various Unix shells as “wildcards” for
filenames, also known as metacharacters
* - mathes 0 or more of any character
ls *.c
? - matches any single character
ls file0?.c
[...] - matches any single character if it is in
the list provided
ls file[0-9].c
Regular Expressions

A formalized way to specify strings





File names (shell commands)
Strings in text files (during editing)
Compilers (future topic)
Sed
Unfortunately, each use defines its own
special metacharacters
Regular Expressions

LS – which files match A*[0-9]?.c







AboutTime.c
AboutTime
A2.c
A2i.c
A211x.c
AllFilesGreaterThan12.c
A2char.c
Regular Expressions

Write a regular expressions for:






All files with an ‘X’ in the name
All files with an ‘X’ and a following ‘Y’
All file names with exactly 6 characters
All file names with more than 6 characters
All files that start with ‘a’ and end with ‘x’
All files names including an ‘a’ but fewer than
10 characters (this one is TOUGH!)
The Manual

The man command

man gcc

Spacebar for next page and return for next


line
q to quit
Also try info

info gcc
grep Commands


grep, egrep, fgrep
grep format:


grep [options] search_string filename(s)
Options:

-c

-l


-n
-v
Prints the count of matching lines rather than
the actual lines
prints the name of each file containing matching
lines, rather than the actual lines
precedes each line with a line number
inverse search, shows all lines that do not
match pattern
sort Command

sort format:


sort [options] filename
Options:






-d
alphabetic, ignore punctuation
-f
ignore case for sorting
-r
reverse sort order
-o outfile output to file, not stdout
-n
arithmetic order
-tc
use ‘c’ to separate fields; default is
whitespace
find Command

find format:


find directory_name search_criteria action
Search Criteria:




name filename
files that match filename
atime +-n files last accessed in days
mtime +-n files last modified in days
follow
follow symbolic links
find Command

Actions:
-print
-exec cmd
-ok cmd
print the files found
execute command on files found
like exec, but prompts to execute
command first
Download