IT 244: Introduction to Linux/Unix
Class 10
Tips and Examples
Review
New Material
Studying
Microphone
Homework 5
I have posted homework 5 here.
It is due this coming Sunday at 11:59 PM.
Quiz 3
I have posted the answers to Quiz 3
here.
Questions
Are there any questions before I begin?
Tips and Examples
Using Pathnames
- If you want to work with a file ...
- you usually go to the directory that contains the file
- When you do this you can use just the name of the file ...
- when you need to run a command on it
- I have some web pages that offer help with Linux
- They are contained in the directory /home/ghoffman/public_html/linux
- One of these files is common_unix_commands.html
- Let's say I wanted to find a mention of the
finger
command on this page
- If I were in the directory that held the file I would simply type
$ grep finger common_unix_commands.html
- If I were in my home directory and I could use a
relative pathname
grep finger public_html/linux/common_unix_commands.html
- The file I want to access is below my current directory
- So the path will list the directories between my current directory ...
- and the directory that contains the file
- What if I wanted you to make a copy of this file to practice with?
- Each of you would be in a different directory when you copied the file
- So I would give each of you an
absolute pathname
- Then you would type
cp /home/ghoffman/public_html/linux/common_unix_commands.html .
Using a Pathname to Run a Script
Practice with Access Permissions
- You will need to know how to use
chmod
to change
access permissions ...
- on the Midterm and Final exams
- You will get some practice with
chmod
in the Class Exercise for this class
- I have also created a web page to give you extra practice with
chmod
- You will find this page here
- The page also has a link to the answers
- There is a link to the
chmod
practice page on the class web page
Review
Access Permissions
- All Unix files and directories have
access permissions
- The access permissions allow the owner control of a file or directory
- They regulate who gets to do what with the file or directory
- The owner of a file or directory is the user account that created it
- Every file, directory or device on a Unix filesystem has three types of permissions
- Each access permission can either be on or off
- If you have read permission
on a file you can look at the data in the file
- If you only have read permission, you cannot change a file
- To change a file you need write permission
- To run a program or script using only its name on the command line ...
- you must have
execute permission on that file
- These permissions apply to three classes of users
- The owner
- The group
- Every other account
- Every file or directory has an owner
- The account that created the file is the
owner
- A group is a collection of Unix accounts
- A group can only be set up by a system administrator
- Every file or directory is assigned to a group
- The last class of users is everyone else
- Any account that is not the owner or a member of the group ...
- is a member of this user class
- It is sometimes called other
Viewing Access Permissions
chmod
Using chmod
with Numeric Arguments
Attendance
New Material
The root Account
Directory Access Permissions
- Directories are a special kind of file
- They do not hold data user data
- They hold the names and internal representation of other files and directories
- Unix permissions work a little differently for directories
- Read and write permissions for a directory are similar to those for a file
- Read permission on a directory allows you to list the contents ...
- using
ls
- So read permission on a directory only allows you to run
ls
on it
- To read the contents of the files in the directory ...
- you need read permission for each file
- Read permission on a directory does not allow you to read the files in that directory
- You need read permission on the file to do that
- Write permission on a directory allows you to create or delete
anything in that directory ...
- and to change the name of anything inside that directory
- But you cannot change the files themselves ...
- unless you have write permission on those files
- Write permission on a directory only applies to the contents of a directory
- Not to the directory itself
- You cannot change the directory name or delete a directory on which
you have write permission
- To do that you have write permission on its parent directory
- Execute permission on a directory ...
- is very different from execute permission on a file
- You can't run a directory from the command line like a program or script
- Execute permission on a directory allows you to
cd
into
that directory ...
- so you can make the directory your current directory
Links
- You can use the link just as if it were a directory
- If you
cd
to the link, you will go to the real directory
- If you then use
pwd
inside the directory you will see
$ pwd
/home/ghoffman/it244
- The path that
pwd
prints ...
- is the route you took to get to the current directory
- But it is not the real path to the directory
- You can only get the true location ,,,
- if you use
pwd
with the -P option
$ pwd
/home/ghoffman/it244
$ pwd -P
/courses/it244/f23/ghoffman/ghoffman
- You must use a capital P, not a lowercase p
- Unix tries to hide your real location when you use a link ...
- so as not to confuse you
- I can get back to where I came from using ..
$ pwd
/home/ghoffman/it244
$ cd ..
$ pwd
/home/ghoffman
- Why does your home directory have a link to your it244 class directory?
- To make things easier for instructors like me
- If you did your work for this course in your home directory ...
- it would make more work for me
- I would have to go to many places to collect your assignments
- Instead I only have to go one place
- And if I run
ls
I see each of your course directories
- The it244 entry in your home directory is a link
- It points to your course directory in /courses/it244/f24/ghoffman
- The name of your course directory is your Unix username
The Two Types of Links
- There are two types of links
- Hard links
- Symbolic, or soft, links
- Hard links are older
- But they are seldom used these days
- A hard link is like a duplicate file name
- If you have a hard link to a file and the original filename is deleted ...
- the file will still be there
- The file will remain until the last hard link is removed
- Hard links have some disadvantages
- Hard links can only point to files, not directories
- Our Unix filesystem appears to be a single hierarchy
- In reality it is a collection of different file systems ..
- on different hard disk volumes
- The different file systems are stitched together ...
- so they look like a single system
- Unix hides this fact from users
- But this causes problems for hard links
- You can only have a hard link to a file in the same volume ...
- as the link you are creating
- That means you can't link to a file on a different disk or partition
- Symbolic links are much more flexible
- Symbolic links are sometimes called soft links
- You can use either an absolute or relative pathname ...
- when creating a symbolic link
- A symbolic link can point to a file or directory on any disk or partition
- Deleting a soft link does not delete the file or directory it points to
- The symbolic link remains but it points to nothing
ln
- Use
ln
to create a link
- To create a symbolic or soft link, use
ln
with the -s option
- Otherwise you will create a hard link
- That is not what you want
ln
takes two arguments
ln -s PATHNAME [LINK_NAME]
- The second argument, the link name, is optional
- If you ommit it, the link name will be the same as the
name of the file or directory ...
- that you are linking to
- Here is an example
$ pwd
/home/it244gh
$ ln -s ~ghoffman/course_files/it244_files examples
$ ls -l examples
lrwxrwxrwx 1 it244gh libuuid 28 2012-09-17 17:53 examples -> /home/ghoffman/examples_it244
Removing a Link
- To delete a link, use
rm
- This will work whether the link points to a file or a directory
- If you delete a symbolic link it will not affect the file or directory it points to
- If you delete a hard link you will not delete the file ...
- unless the link is the last connection to the file
Setuid and Setgid Permissions
Setting Setuid and Setgid with chmod
Studying
Class Exercise
Class Quiz