IT 244: Introduction to Linux/Unix 
		    Class 11
		
	
	
     Today's Topics
    Tips and Examples
    
    
    Review
    
    
    New Material
    
    
    Reading Assignment
    The reading assignment for this week is chapter 5 of Sobell, 
            The Shell.
    
    Homework 6
    I have posted homework 6 here.
    It is due this coming Sunday at 11:59 PM.
    
    Mid-term
    The mid-term exam for this course will be held on Tuesday, October  24th.
    It will consist of 25 questions like those on the quizzes.
    You will have the entire class period to work on the exam.
    60% of the questions will come from the Ungraded Class Quizzes.
    The last class before the exam, Thursday, October  19th, will be a review session.
    You will only be responsible for the material in the Class Notes for that class
       on the exam.
    
    The Mid-term is a closed book exam.
    
    Quiz 3
    I have posted the answers to Quiz 3 here.
    
    Tips and Examples
    
    Viewing Directory Permissions
    
        - If you run ls -lon a directory ...
- it will show the permission of everything inside that directory
- What if you wanted to see the permission on the directory itself
- You have two options
- You can run ls -lon the parent directory ...
- or you can run ls -ld
- The -doption tellsls...
- to display the directory ...
- not the things inside the directory
- So if I were in a directory that contained another directory named dir
        	
$ ls
dir  test 
- and I ran ls -lon dir ...
- it would show me the permission on everything inside dir ...
- not on dir itself
        	
$ ls -l dir
total 0
-rw-rw-r-- 1 ghoffman faculty 0 Oct  7 21:56 bar.txt
-rw-rw-r-- 1 ghoffman faculty 0 Oct  7 21:56 foo.txt 
- I could run lson the parent directory
$ ls -l
total 2
drwxrwxr-x 2 ghoffman faculty 512 Oct  7 21:56 dir
drwxrwxr-x 2 ghoffman faculty 512 Oct  7 22:10 test 
- or run ls -lddirectly on the directory
$ ls -ld dir
drwxrwxr-x 2 ghoffman faculty 512 Oct  7 21:56 dir 
Never Use . . in an Absolute Pathname
    
    
    Write Permissions on a Directory
           
        - Write permission on a directory only applies to the content of the directory
- It does not apply to the directory itself
- If you have write permission on a directory you can
                   
                - Create a file or directory inside the directory
- Delete a file or directory inside the directory
- Rename a file or directory inside the directory
 
- In order to delete of change the name of the directory itself ...
- you must have write permission on the parent directory
Using the ls Command
           
        - You don't have to be in a directory to run lson it
- If you run lswithout an argument ...
- it will list the contents of your current directory
- But if you give lsa directory pathname ...
- it will list the contents of that directory
            
$ ls ~tsoro/course_files/
cs115_files  it244_files  it341_files 
- If you want to see the access permissions on the directory it244_files ...
- you might  be tempted to run ls -lon this directory ...
- but if you did you would not get the permissions on it244_files
        
$ ls -l ~tsoro/course_files/it244_files/
total 57
-rwxrwxr-x 1 ghoffman faculty  163 Sep 15 12:48 bother10.sh
-rwxrwxr-x 1 ghoffman faculty  131 Sep 15 12:48 bother.sh
-rwxrwxr-x 1 ghoffman faculty  167 Sep 15 12:48 break.sh
... 
- Instead you see the permissions on the contents of it244_files
- To see the permissions for the directory itself ...
- and not the contents of the directory
- you need to use the -d (directory) option along with the -l option
            
$ ls -ld ~tsoro/course_files/it244_files
drwxrwxr-x 6 ghoffman faculty 1536 Sep 15 12:51 /home/ghoffman/course_files/it244_files 
The chmod Chant
    
    
    Using . When Copying a File
    
    
    Review
    
    The root Account
           
        - On every Unix or Linux system there is a special account named 
            root
        
- root can access any file ...
- or run any program
- root is an administrator account
- It is used for system configuration and maintenance
- Even a system administrator should not log in as root
- Instead he or she should use a regular Unix account ...
- and use sudowhen running a command ...
- that needs root privileges
- sudoallows a user to run a command ...
- that normally only root can run
- When you run sudoit asks you for your password ...
- not the password of the root account
- In order to run sudoyou must be on the sudoers list ...
- a change which only the root account can make
Setuid and Setgid Permissions
           
        - Sometimes a program needs to read or modify a file ...
- to do the work it was designed to do
- For example the passwdcommand ...
- which is used to change the password for an account ...
- has to make changes to the file /etc/shadow
- When you need to change your password you run passwd
- But /etc/shadow is owned by the root account ...
- and no other account can change it
- To deal with situations like this, two special permissions were created 
            
        
- If a program file has setuid permission ...
- anyone who runs the program ...
- has all the permissions of the owner of that file ...
- but only while the file is running
- This permission means it can change any other files ...
- that the script or program needs to do its job
- If a program file has setgid permission set ...
- anyone who runs the program ...
- has the permissions of the group assigned to that file...
- while the file is running
- setuid and setgid permissions are only given to executable files ...
- that is, programs and scripts
- But while the permission is set on the executable files ...
- it works on other files ...
- which the executable file has to change
- A file with setuid permission ...
- will have s 
            in place of x ...
        
- in the column for the owner's execute permission
- A file with setgid permission ...
- will have s 
            in place of x ...
- for the group execute permission
- Since setuid and setgid permission ...
- apply only to executable files ...
- there is no ambiguity in replacing x 
            with s
        
Directory Access Permissions
           
        - The Unix access permissions 
            work a little differently for directories ...
        
- than they do for files
- Read and write permissions for a directory are similar to those for a file
- Read permission allows you to list the contents of that directory using ls
- Write permission allows you to create, delete ...
- or change the name of entries in that directory
- Write permission on a directory ...
- does not allow you to change the contents of a file ...
- in that directory
- If you have write permission on a directory you can change what's inside it ...
- but you cannot rename the directory or delete it ...
- unless you have write permission on its parent directory
- Execute permission on a directory allows you to do two things
- It allows you to enter that directory using cd
- It also allows you to read a file in that directory
- if you already have read permission on that file ...
- or change the contents of a file if you have write permission
- Without execute permission on a directory ...
- you cannot access any file in that directory
Links
           
        - Links are like shortcuts on a Windows machine
- or aliases on a Mac
- Links allow you to move around the filesystem using short names
- Each of you has an entry in your home directory called it244
- In the home directory of my test account, it244gh, I have such a link
            
$ ls -l it244
lrwxrwxrwx 1 ghoffman faculty 36 Oct  5 11:42 it244 -> /courses/it244/sum17/ghoffman/ghoffman 
- This is a link to/courses/it244/sum17/ghoffman/ghoffman 
- If you cdinto this location and usepwd
$ cd it244
    
$ pwd
/home/tsoro/it244
- This path reflects the route you took to get here
- But it is not the real pathname of the directory
- You can only get that information if you use pwdwith the -P (note the capitalization) option   
$ pwd -P
/courses/it244/sum17/ghoffman/ghoffman 
The Two Types of Links
           
        - There are two types of links
                   
                - Hard links
- Symbolic, or soft, links
 
- Hard links are older
- A hard link is like a duplicate file name
- Hard links can only point to files ...
- not directories
- You can only have a hard link to a file ...
- if that file is on the same hard disk volume ...
- as the link
- Symbolic links are much more flexible
- You can use either an absolute or relative pathname ...
- when creating a symbolic link
- A symbolic link can point to a file or directory anywhere in the filesystem
- Deleting a symbolic link does not delete the file or directory it points to
ln
    
    
    Removing a Link
           
        - To delete a link, use rm
- If you delete a symbolic link ...
- it will not affect the file or directory it points to
New Material
	
	Syntax of the Command Line
	
    
    Command Options
           
        - Many commands have options
- Options modify the behavior of the command
- Options are usually preceded by one or two dashes, -
- GNU programs frequently have options that are preceded by two dashes, --
- The options in GNU programs are usually words
- The options in other Unix programs are usually a single letter
- When a command uses a single dash, -, before an option ...
- you can usually combine options ...
- behind a single -
- An example of this is ls -ltr
- This means run ls       
                - To get a long listing
- Sorted by modification date and time
- In reverse order
 
- Options using two dashes, --, cannot usually be combined
- In this case, each option must be written separately ...
- and preceded by two dashes
- Sometimes the option can have it's own argument
- When this happens, the argument is usually separated from the option by spaces
            
gcc  -o  prog  prog.c 
- Utilities that report the size of files usually do so in bytes
- This works well with small files
- But with large files, a size in bytes can be hard to read
- Such utilities often have a -h, or--human-readable, option
- With this option, the file size will be displayed ...
- in kilobytes, megabytes or gigabytes, as appropriate
- df(disk free) shows the amount of space on the various filesystems- 
$ df 
Filesystem                       1K-blocks     Used Available Use% Mounted on
/dev/sda1                         12253360  6027788   5580096  52% /
none                                     4        0         4   0% /sys/fs/cgroup
udev                               2013316        4   2013312   1% /dev
tmpfs                               404836      560    404276   1% /run
none                                  5120        0      5120   0% /run/lock
none                               2024172        0   2024172   0% /run/shm
none                                102400        0    102400   0% /run/user
blade66:/disk/sd0g/courses/it244   8260768  2615904   5562240  32% /courses/it244
blade82:/disk/sd0f/home/jdu        8260768  8171264      6912 100% /home/jdu
mx1:/disk/sd1e/spool/mail          4129312  3403648    684384  84% /spool/mail
blade82:/disk/sd1h/home/ghoffman  78805984 32988544  45029408  43% /home/ghoffman 
- When used with the -h opition ...
- dfproduces more readable output- 
$ df -h
Filesystem                        Size  Used Avail Use% Mounted on
/dev/sda1                          12G  5.8G  5.4G  52% /
none                              4.0K     0  4.0K   0% /sys/fs/cgroup
udev                              2.0G  4.0K  2.0G   1% /dev
tmpfs                             396M  568K  395M   1% /run
none                              5.0M     0  5.0M   0% /run/lock
none                              2.0G     0  2.0G   0% /run/shm
none                              100M     0  100M   0% /run/user
blade66:/disk/sd0g/courses/it244  7.9G  2.5G  5.4G  32% /courses/it244
blade82:/disk/sd0f/home/jdu       7.9G  7.8G  6.8M 100% /home/jdu
mx1:/disk/sd1e/spool/mail         4.0G  3.3G  669M  84% /spool/mail
blade82:/disk/sd1h/home/ghoffman   76G   32G   43G  43% /home/ghoffman 
- The -halso works withls
- If I run ls -lon a directory ...
- the file size will be given in bytes
			
$ ls -l
total 1236
-rw-rw-r-- 1 ghoffman faculty 26211 Jun 12 09:23 01_class_notes_it244.html
-rw-rw-r-- 1 ghoffman faculty 26138 Jun 21 15:25 02_class_notes_it244.html
-rw-rw-r-- 1 ghoffman faculty 29395 Jun  6 11:21 03_class_notes_it244.html
... 
- But if I use ls -lh ...
- I get a much more readble result
			
$ ls -lh
total 1.3M
-rw-rw-r-- 1 ghoffman faculty  26K Jun 12 09:23 01_class_notes_it244.html
-rw-rw-r-- 1 ghoffman faculty  26K Jun 21 15:25 02_class_notes_it244.html
-rw-rw-r-- 1 ghoffman faculty  29K Jun  6 11:21 03_class_notes_it244.html 
- Many commands display a help message when run with the --help option
        	
$ mkdir --help
Usage: mkdir [OPTION]... DIRECTORY...
Create the DIRECTORY(ies), if they do not already exist.
Mandatory arguments to long options are mandatory for short options too.
  -m, --mode=MODE   set file mode (as in chmod), not a=rwx - umask
  -p, --parents     no error if existing, make parent directories as needed
  -v, --verbose     print a message for each created directory
  -Z, --context=CTX  set the SELinux security context of each created
                      directory to CTX
      --help     display this help and exit
      --version  output version information and exit
Report mkdir bugs to bug-coreutils@gnu.org
GNU coreutils home page: <http://www.gnu.org/software/coreutils/>
General help using GNU software: <http://www.gnu.org/gethelp/>
For complete documentation, run: info coreutils 'mkdir invocation'
- All GNU utilities accept this option
tty
           
        - As you type at the command line ...
- the characters you type are collected by a program called tty
- ttyis a device driver 
            that is part of the 
            kernel
- It looks at each character as you type ...
- and takes appropriate action
- Most of the time, ttyjust places the character in a 
        	buffer
- A buffer is a space in memory ...
- that holds data for later processing
- But ttyresponds differently to special characters
- When the character you type is the backspace ...
- it erases the previous character from the buffer
- When the character is the Control U ...
- ttyerases the buffer from the current insertion point ...
- to the beginning of the line
- ttyis responsible for all 
            command line editing
- When ttysees a newline character ...
- it passes the contents of the buffer to the shell
- Newline is the character you get from hitting Enter on a windows machine ...
- or Return on a Mac
Parsing the Command Line
           
        - The shell takes the contents of the buffer ...
- and breaks it up into tokens
- Tokens are the strings of text separated by spaces or tabs
- This action is called 
            parsing
        
- So parsing the act of making a list of all the strings ...
- on the command line ...
- and throwing away the whitespace
- Next, the shell looks for the name of the command
- Usually, the command name is the first string on the command line
- The command can be specified by a simple filename
            
ls 
- Or by using a pathname to the executable file
            
/bin/ls 
The PATH System Variable
    
    
    Running a Program in the Current Directory
     
    
    Running the Command Entered on the Command Line
	
    
    
    Attendance
    
    Class Quiz