credit where credit is due
play

Credit Where Credit is Due These slides for CSC209H have been - PDF document

Credit Where Credit is Due These slides for CSC209H have been developed by Sean Culhane, a Introduction to previous instructor: I have modified them for this presentation of the course, but must acknowledge their origins! UNIX S -1 S -2


  1. Credit Where Credit is Due • These slides for CSC209H have been developed by Sean Culhane, a Introduction to previous instructor: I have modified them for this presentation of the course, but must acknowledge their origins! UNIX S -1 S -2 Logging in Shells • Login name, password • Bourne shell, C shell, Korn shell, tcsh System password file: usually “ /etc/passwd ” • – command line interpreter that reads user input and executes commands • /etc/passwd has 7 colon-separated fields: > ls -l /var/shell total 6 maclean:x:132:114:James MacLean: lrwxrwxrwx 1 root 12 May 15 1996 csh -> /usr/bin/csh ^^^1^^^ 2 ^3^ ^4^ ^^^^^^5^^^^^^ lrwxrwxrwx 1 root 12 May 15 1996 ksh -> /usr/bin/ksh /u/maclean:/var/shell/tcsh lrwxrwxrwx 1 root 17 May 15 1996 newsh -> /local/sbin/newsh ^^^^^6^^^^ ^^^^^^^7^^^^^^^ lrwxrwxrwx 1 root 11 May 15 1996 sh -> /usr/bin/sh lrwxrwxrwx 1 root 15 May 15 1996 tcsh -> /local/bin/tcsh 1: user name 5: “in real life” 2: password (hidden) 6: $HOME 3: uid 7: shell 4: gid S -3 S -4 newsh “man page” Files and Directories newsh • UNIX filesystem is a hierarchical arrangement of directories & files newsh - shell for new users • Everything starts in a directory called root whose name is the single SYNOPSIS character / newsh • Directory: file that contains directory entries DESCRIPTION newsh shows the CDF rules, runs passwd to force the user to • File name and file attributes change his or her password, and runs chsh to change the – type user's shell to the default system shell (/local/bin/tcsh). – size FILES – owner /etc/passwd – permissions SEE ALSO passwd(1), chsh(1) – time of last modification HISTORY Written by John DiMarco at the University of Toronto, CDF S -5 S -6 1

  2. Files: an example Directories and Pathnames > stat /u/maclean • Command to create a directory: mkdir • Two file names automatically created: – current directory (“ . ”) File: "/u/maclean" -> "/homes/u1/maclean" Size: 17 Allocated Blocks: 0 Filetype: Symbolic Link – parent directory (“ .. ”) Mode: (0777/lrwxrwxrwx) Uid: ( 0/ root) Gid: ( 1/ other) Device: 0/1 Inode: 221 Links: 1 Device type: 0/0 A pathname is a sequence of 0 or more file names, separated by / , Access: Sun Sep 13 18:32:37 1998 • Modify: Fri Aug 28 15:42:09 1998 optionally starting with a / Change: Fri Aug 28 15:42:09 1998 – absolute pathnames: begins with a / – relative pathnames: otherwise S -7 S -8 Working directory Permissions • Current working directory (cwd) • When a file is created, the UID and GID of the creator are remembered – directory from which all relative pathnames are interpreted • Every named file has associated with it a set of permissions in the form of a string of bits: • Change working directory with the command: cd or chdir rwxs rwxs rwx Print the current directory with the command: pwd • owner group others • Home directory: working directory when we log in mode regular directory – obtained from field 6 in /etc/passwd r read list contents Can refer to home directory as ~maclean or $HOME • w write create and remove x execute search s setuid/gid n/a • setuid/gid executes program with user/group ID of file’s owner • Use chmod to change permissions S -9 S -10 Input and Output Basic UNIX Tools man ("man -k", "man man") (1.13) • File descriptor ls -la ("hidden files") – a small non-negative integer used by kernel to identify a file cd pwd • A shell opens 3 descriptors whenever a new program is run: du, df – standard input (normally connected to terminal) chmod – standard output cp, mv, rm (in cshrc: "alias rm rm -i" ... ) – standard error mkdir, rmdir (rm -rf) diff • Re-direction: ls >file.list grep sort S -11 S -12 2

  3. More Basic UNIX Tools C Shell Commands more, less, cat which head, tail, wc echo compress, uncompress, bg, fg, jobs, kill, nice gzip, gunzip, zcat alias, unalias lpr, lpq, lprm dirs, popd, pushd quota -v a209xxxx exit pquota -v a209xxxx source logout, exit rehash mail, mh, rn, trn, nn set/unset who, finger date, password S -13 S -14 Additional Commands arch Introduction to the cal ps C Shell hostname clear tar uptime xdvi gs, ghostview setenv, printenv S -15 S -16 What is the Shell? csh Shell Facilities • A command-line interpreter program that is the interface between the • Automatic command searching (6.2) user and the Operating System. • Input-output redirection (6.3) • The shell: • Pipelining commands (6.3) – analyzes each command • Command aliasing (6.5) – determines what actions to be performed • Job control (6.4) – performs the actions • Command history (6.5) • Example: • Shell script files (Ch.7) wc -l file1 > file2 S -17 S -18 3

  4. I/O Redirection Pipes • stdin (fd=0), stdout (fd=1), stderr (fd=2) • Examples: who | wc -l Redirection examples: ( < , > , >> , >&, >!, >&! ) • ls /u/csc209h |& sort -r fmt • For a pipeline , the standard output of the first process is connected to fmt < personal_letter the standard input of the second process fmt > new_file fmt < personal_letter > new_file fmt >> personal letter fmt < personal_letter >& new_file fmt >! new_file fmt >&! new_file S -19 S -20 Filename Expansion Command Aliases • Examples: • Examples: ls *.c alias md mkdir rm file[1-6].? alias lc ls -F cd ~/bin alias rm rm -i ls ~culhane \rm *.o unalias rm * Matches any string (including null) alias ? Matches any single character alias md [...] Matches any one of the enclosed characters alias cd 'cd \!*; pwd' [.-.] Matches any character lexically between the pair [!...] Matches any character not enclosed S -21 S -22 Job Control Some Examples a | b | c • A job is a program whose execution has been initiated by the user – connects standard output of one program to standard input of another • At any moment, a job can be running or stopped (suspended) – shell runs the entire set of processes in the foreground • Foreground job: – prompt appears after c completes a & b & c – a program which has control of the terminal – executes a and b in the background and c in the foreground • Background job: – prompt appears after c completes – runs concurrently with the parent shell and does not take control of the keyboard a & b & c & Initiate a background job by appending the “ & ” metacharacter • – executes all three in the background Commands: jobs , fg , bg , kill , stop • – prompt appears immediately a | b | c & – same as first example, except it runs in the background and prompt appears immediately S -23 S -24 4

  5. Shell Variables The History Mechanism (setting) • Example session: • Examples: alias grep grep -i set V grep a209 /etc/passwd >! ~/list set V = abc history set V = (123 def ghi) cat ~/list set V[2] = xxxx !! set !2 unset V !-4 !c !c > newlist grpe a270 /etc/passed | wc -l ^pe^ep S -25 S -26 Shell Variables Shell Control Variables (referencing and testing) filec a given with tcsh • Examples: echo $term prompt my favourite: set prompt = “%m:%~%#” echo ${term} ignoreeof disables Ctrl-D logout echo $V[1] history number of previous commands retained echo $V[2-3] mail how often to check for new mail echo $V[2-] path list of directories where csh will look for commands ( † ) set W = ${V[3]} noclobber protects from accidentally overwriting files in redirection noglob turns off file name expansion set V = (abc def ghi 123) set N = $#V echo $?name • Shell variables should not to be confused with Environment variables. echo ${?V} S -27 S -28 Variable Expressions File-oriented Expressions • Examples: Usage: set list1 = (abc def) -option filename set list2 = ghi where 1 (true) is returned if selected option is true, and 0 (false) otherwise set m = ($list2 $list1) -r filename Test if filename can be read -e filename Test if filename exists @ i = 10 # could be done with “set i = 10” -d filename Test if filename is a directory @ j = $i * 2 + 5 -w filename Test if filename can be written to @ i++ -x filename Test if filename can be executed -o filename Test if you are the owner of filename comparison operators: ==, !=, <, <=, >, >=, =~, !~ • • See Wang, table 7.2 (page 199) for more S -29 S -30 5

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend