Download presentation
Presentation is loading. Please wait.
Published byJocelin Fitzgerald Modified over 9 years ago
1
UNIX An Introduction
2
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, 1995 http://www.computerhope.com/history/unix.htm http://www.computerhope.com/history/unix.htm
3
UNIX Philosophy Simplicity Simplicity Reusability Reusability Filters Filters Open Formats Open Formats Flexibility Flexibility
4
What is the shell? Utility program loaded when a user logs in init getty login sh (bash) startup
5
Shell’s Responsibilities Shell Program Execution variable and filename substitution I/O Redirection pipeline hookup environment control interpreted programming languages
6
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 * - matches 0 or more of any characters 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
7
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
8
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
9
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!)
10
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
11
Linux Commands File manipulation File manipulation rm, mv, cat, cp, chmod rm, mv, cat, cp, chmod Navigation Navigation cd, pushd, popd cd, pushd, popd System information System information ls, wc, top, ps ls, wc, top, ps
12
File Manipulation vi (or your editor of choice) vi (or your editor of choice) touch touch mkdir, rmdir mkdir, rmdir cp, rm cp, rm chmod, chown chmod, chown Permissions Permissions read, write, execute; owner, group, user read, write, execute; owner, group, user -rw-r--r-- = 644 -rw-r--r-- = 644
13
File Information ls ls more more wc wc cat cat head head tail tail du du df df
14
File System Directory Structure is a tree Directory Structure is a tree All items in hierarchy are files All items in hierarchy are files Files represented by inode – ls –I Files represented by inode – ls –I Multiple “files” (names) to an inode Multiple “files” (names) to an inode
15
Example File Tree / /home /dev /usr /home/akl /home/sweany public classes 3600
16
Moving between locations The cd command changes directory The cd command changes directory cd cd cd pathname cd pathname pushd pathname pushd pathname popd pathname popd pathname
17
Pathnames Two ways to specify : Two ways to specify : Absolute pathnames start with a slash (/). Absolute pathnames start with a slash (/). Relative pathnames don’t. Relative pathnames don’t. Example absolute pathnames : Example absolute pathnames : /home/s3/Empdata/dbs /home/s3/Empdata/dbs /etc/passwd /etc/passwd Example relative pathnames Example relative pathnames programs/tsp.c programs/tsp.c......./../programs/tsp.c../../programs/tsp.c ~
18
File Permissions File Permissions chmod mode filename(s) chmod mode filename(s) umask – specifies default file permissions umask – specifies default file permissions ls –l displays detailed file information ls –l displays detailed file information $ ls -l -rwxr-xr-x 1 s3 students 892 Feb 8 10:15 memo drwxrwxrwx 1 s3 students 1024 Dec 10 8:05 progs
19
Special Files Dot files – filename starts with ‘.’ Dot files – filename starts with ‘.’ ls -a ls -a.bash_history.bash_history.bash_login.bash_login.profile – MAY not be writeable by user.profile – MAY not be writeable by user
20
My.profile alias rm’/bin/rm’ PATH=.:/usr/local/bin:/usr/bin:/home/sweany/bin
21
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
22
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
23
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
24
find Command Actions: Actions: -printprint the files found -exec cmdexecute command on files found -ok cmdlike exec, but prompts to execute command first
25
Find Examples ix% find programs –name “*.c” –print ix% find. -name “*.c” –exec rm –rf {} \; ix% find. -mtime -3 -print
26
Type Conversion doubleatof (char *nptr) longatol (char *str) intatoi (char *str)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.