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