IT 244: Introduction to Linux/Unix
Class 9
Today's Topics
Tips and Examples
Review
New Material
Reading Assignment
The reading assignment for this week is chapter 4 of Sobell,
The Filesystem.
Homework 5
I have posted homework 5 here.
It is due this coming Sunday at 11:59 PM.
Quiz 2
Let's look at the answers to
Quiz 2.
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.
Tips and Examples
Testing Your Class Exercises
A Subtle Pathname Problem
- Several semesters ago a student came to me with a problem ...
- that took me a few minutes to unravel
- It all had to do with the absence of one character in a pathname
- The student was trying to go to his it244 directory using the command
cd ~/it244
- Once there he tried to create a file using the
touch
command ...
- but he got an error message saying he didn't have permission
- After staring at his prompt for a few minutes ...
- I realized what was going on
- The student thought he had entered
cd ~/it244
- which would have put him in his it244 directory
- What he really typed was
cd ~it244
- which took him to the home directory of the it244 account, /home/it244
- This account was created by Prof. Bo Sheng ...
- who also teaches this course
- It is a dummy account that he uses for teaching and testing ...
- like my it244gh account
- The only account that can create a file in this directory ...
- is the account for which the home directory was created
- Here again a single character was the source of the problem
Review
Hidden Filenames
- A file whose filename begins with a period, . , is a "hidden" or "invisible" file
ls
does not display these files unless you use the -a
option
- These files are used to configure your Unix environment
Startup Files
- Files like .login and .bash_profile ...
- which appear in your home directory ...
- are startup files
- They contain Unix commands ...
- that are run before you get the first shell prompt
- These commands customize your Unix environment
- Among other things, you can set Unix variables ...
- which can help you with your work
The . and .. Directory Entries
- Every directory has at least two entries . and ..
- When a new directory is created ...
- these are the first two entries
- . stands for the current directory
- . . stands for the parent directory of your current directory
- . . is the directory immediately above your current location
- . is most often used in two circumstances
- To run a program in your current directory
- To move or copy a file to your current directory
Pathnames
- Every file has a
pathname which is used to access the file
- A pathname has two components
- A path to reach the file
- The name of the file
- The path is a list of directories that you must go through ...
- to reach the file you want
- A pathname is like an address on a letter ...
- a name and directions to get there
- The name of the file is always at the end of a pathname
- When the slash, / appears between names in a pathname ...
- it is used to separate a directory name ...
- from what comes after it
- When a / is the first character in a pathname ...
- it stands for the root directory
- There are two types of pathnames
Absolute Pathnames
- The top of the filesystem is a directory called the root directory
- The root directory is represented by a single slash character, /
- It can stand alone ...
- or appear as the first character before a directory name
- An absolute path
is a list of directories ...
- starting with the root directory ...
- and ending with the directory that contains the file
- When you add the filename to the end of an absolute path ...
- you have an absolute pathname
Tilde ~ in Pathnames
- There is one form of absolute path that is very short
- This is the tilde character, ~
- Tilde stands for your home directory
- This means you can use tilde, ~ ...
- anywhere you would normally use a path to your home directory
- When you put a tilde in front of a Unix username ...
- it stands for the home directory of that account
- ~ always means an absolute path
Relative Pathnames
- Absolute pathnames are useful because you can use them anywhere
- But they are long and easy to mistype
- For most purposes, it is easier to use
relative pathnames
- In a relative pathname, the path starts from your current directory
- In an absolute pathname, the path starts from the root, /
- While all absolute pathnames start with a slash, /,
or a tilde, ~ ...
- relative pathnames never do
- As far as Unix is concerned it makes no difference ...
- whether you use and absolute or relative pathname
- There are four types of relative pathnames:
- When the file is in your current directory
- When the file is in a subdirectory of your current directory
- When the file is in a directory that is above your current directory
- When the file is in a directory that is neither above or below the current directory
Relative Pathnames in Your Current Directory
- A relative pathname of a file or directory ...
- inside your current directory ...
- is simply the name of that file or directory
Relative Pathnames in a Subdirectory
- Things get a little more complicated ...
- when you are dealing with a file in a subdirectory
- Here, you must list every directory ...
- between your current directory ...
- and the file you want
- You must use a slash, / ...
- to separate the name of each directory ...
- from what comes after it
Relative Pathnames above the Current Directory
- When the file or directory is above the current directory ...
- you can't list the directory names
- Instead, you have to use the special .
. entry in each directory
- Use one . . for each directory up the chain in the path
- Use a slash, /, between each ..
Relative Pathnames Neither above Nor below the Current Directory
- What if the file is neither above nor below?
- Here you have to go up to a common ancestor ...
- and then down to the directory that holds what you want
- The path starts with one or more . .
- You keep going up ...
- until you get to a directory ...
- that is both an ancestor of your current directory ...
- and the file you are trying to reach
- Once you get to the common ancestor ...
- you go down to the directory that holds the file
New Material
Access Permissions
- All Unix files and directories have
access permissions
- The access permissions allow the
owner of a file or directory ...
- to decide who gets to do what with the file or directory
- By default, the owner of a file or directory ...
- is the account that created it
- Every file, directory or device on a Unix filesystem
- has three types of permissions
- If you have read permission on a file ...
- you can look at the data in the file
- You can run
cat
, more
or less
on these files
- If you only have read permission on a file ..,
- you cannot change it
- To change a file you need
write permission
- To run a program or script file ...
- you must have execute permission
- Each of the three types of permissions ...
- are set either on or off ...
- to three classes of users
- The owner
- The group
- Every other Unix account
- Every file or directory has an owner ...
- and a group assigned to it
- The account that created the file is usually the owner
- A group
is a collection of Unix accounts
- Every account also has a default group ...
- that is assigned to every file or directory ...
- that account creates
- This default group is created when the account is created
- Only a system administrator can add users to a group
- Every file or directory is assigned to a group ...
- though the owner can change this to another group
- The last class of users is any account ...
- that is not the owner or a member of the group
- Unix calls this class of users "other"
Viewing Access Permissions
chmod
Using chmod
with Numeric Arguments
- The numeric permissions format uses three digits
- Each digit is a number from 0 to 7
- The first digit gives the permissions of the owner
- The second digit gives the permissions assigned to the group
- The third digit gives the permissions for every other account
- Each of these classes of users must be assigned values ...
- for read, write and execute permissions
- How do you get three pieces of information out of one number?
- By adding powers of two
- Each digit is the sum of three other numbers
- When calculating the number you add
- 4 if you want to give read permission
- 2 if you want to give write permission
- 1 if you want to give execute permission
- Notice that all the number are powers of two
- If we write these values in binary notation
- 100 represents 4
- 010 represents 2
- 001 represents 1
- A single decimal digit from 0 to 7 is represented by 3 binary digits
- This is how we get three pieces of information out of one digit
- For example, to give full permissions I would add
- 4 for read permission
- 2 for write permission
- 1 for execute permission
- So the total, 7...
- which is 111 in binary ...
- grants all three permissions
- Let's look at some other digits
- 6 in binary is 110
- The leftmost digit is 1 indicating read permission
- The center digit is 1 indicating write permission
- The last digit is 0 indicating that execute permission is not granted
- 5 in binary is 101
- The first digit is 1 so read permission is granted
- The second digit is 0 so write permission is not granted
- The last digit is 1 so execute permission is granted
- This scheme is confusing when you first encounter it
- But it becomes easier as you use it
- Try to remember this chant
4 2 1
read write execute
owner group everyone
- Repeat this to yourself several times and it should sink in
- Remember that you need three of these digits ...
- to specify the full permissions for a file or directory
- Let's look at some examples
- When you create a new file, it will have certain default permissions
$ touch foo.txt
$ ls
foo.txt
$ ls -l
total 0
-rw-r--r-- 1 it244gh libuuid 0 2012-02-09 15:51 foo.txt
- The owner can read and write the file, but not execute it
- The group and everyone else can only read the file
- To make the file unreadable to everyone except the owner
$ ls -l
total 0
-rw-r--r-- 1 it244gh libuuid 0 2012-02-09 15:51 foo.txt
$ chmod 600 foo.txt
$ ls -l
total 0
-rw------- 1 it244gh libuuid 0 2012-02-09 15:51 foo.txt
- To change the file back to its default permissions
$ ls -l
total 0
-rw------- 1 it244gh libuuid 0 2012-02-09 15:51 foo.txt
$ chmod 644 foo.txt
$ ls -l
total 0
-rw-r--r-- 1 it244gh libuuid 0 2012-02-09 15:51 foo.txt
chmod
Practice
Attendance
Class Quiz