Additional notes… - University of Texas at Dallas

Download Report

Transcript Additional notes… - University of Texas at Dallas

Chapter 3 Some additional notes…
•
File permissions
A file has three types of permissions (read, write and execute).
Available to three categories of users (user, group and others).
•
Can see the permission settings using ls –l
{apache:~/public_html/CS3375} ls -l
total 6428
-rw-r--r-- 1 kkhan cs
3961 Jan 29 20:58 3375.html
-rw-r--r-- 1 kkhan cs
70656 Jan 21 03:11 Syllabus_3375_sp08.doc
-rw-r--r-- 1 kkhan cs
763392 Jan 7 13:27 Your_UNIX_2e.ppt
- r-x
Owner can read and
- - - execute
--this file
The total line tells how many blocks (usually 1024 bytes per block) are contained in
this directory.
Directory, followed by three sets of 3 bits indicating permissions
First set? Owner
Second set? Group
Third set? Others
r stands for read, w stands for write, x stands for execute
Chapter 3 Some additional notes…
Copying
Permissions
As one other shortcut, it’s possible to tell chmod “give users of one class the same
permissions that some other class has.”
Let’s say we have these files:
d------rwx joe acctg sales
-rw-r--r-- joe acctg info.dat
The other users have full permissions on the sales directory.
We’d like to say “ the user and group should be assigned (=) the permissions
belonging to others.” That translates to:
chmod ug=o
Similarly, to make info.dat readable and writable to the group, we can say:
chmod g=u info.dat (you can read this as “the group is assigned (=) the permissions
currently held by the user.”)
You may also use + and - to add and subtract the permissions that currently belong
to a different class of user.
You can’t mix the standard permissions (r, w, and x) with the coyping shortcuts.
chmod will protest if you give it something like this:
chmod g=wu info.dat
Need to be able to change the file permissions
• Why?
– Protect files from accidental deletion or modification
(archive)
– Allow team members to read, modify, execute, possibly even
delete a file without having to send them a copy
– Setting up your webpage on unix – have to make the html
files accessible or no one will be able to see it!
– …
• Unix command is chmod
– Command allows us to change the permission settings
• Examples (can use relative or absolute permissions):
chmod o+rwx testfile1
-r-x---rwx 1 kkhan cs
24 Sep 7 10:41 testfile1
// “o” is for “other”, “+” means add permission
Need to be able to change the file permissions
• Examples cont.
Change it back?
chmod o-rwx testfile1
Results in:
-r-x------ 1 kkhan cs
24 Sep 7 10:41 testfile1
// “-” means remove permission
Can also use absolute (binary) mode
chmod 507 testfile1
Results in:
-r-x---rwx 1 kkhan cs
24 Sep 7 10:41 testfile1
5
0
7
101 000 111
r-x - - - rwx
(Bits are set or cleared)
Need to be able to change the file permissions
• Access to files is not independent of the permissions
on the directories
• The directory is the “parent”; permissions on the
parent cannot be over-ridden by permissions on its
files
• Examples
• Directory is set with no write access
– Cannot add or delete a file in the directory no matter what its
permissions are
• Question: could we edit a file in this directory?
– Only if we have write permission for the file
• Directory is set with no read or execute access
– Question: could we run an html file in this directory?
– No (this is a common problem setting up webpages)
Need to be able to change the file permissions
• Man chmod
chmod [-fR] absolute-mode file...
chmod [-fR] symbolic-mode-list file...
-f Force. chmod will not complain if it fails to change
the mode of a file.
-R Recursively descends through directory
arguments, setting the mode for each file as
described above.
Problem: I’m building my website and I want to set all
my files in the directory public_html so everyone can
read and execute my html file
chmod –R a+rx public_html
Review: chmod Solves Problems
http://catcode.com/teachmod/no_prob.html
File Permission Exercise
Set the permissions as follows:
testdir1
testfile1.html
testfile2.html
testfile3.html
testfile4.html
testfile5.html
testfile6.html
testfile7.html
testfile8.html
group & other has no access
group & other has no access
group & other has read access
group & other has write access
group & other has execute access
group & other has read and execute access
group & other has read and write access
group & other has write and execute access
group & other has read, write, and execute access
File Permission Exercise
testdir2
// 8 files
group & other has read access
testdir3
// 8 files
group & other has write access
testdir4
// 8 files
group & other has execute access
testdir5
// 8 files
group & other has read and execute access
testdir6
// 8 files
group & other has read and write access
testdir7
// 8 files
group & other has write and execute access
testdir8
group & other has read, write, and execute access
File Permission Exercise
Now, try to:
display the contents of each directory
e.g., ls testdir1
display a long listing of each directory
e.g., ls –l testdir1
why don’t these two list commands behave the same way?
display the contents of each file in each subdirectory
e.g., more testfile1.html
change the contents of each file
e.g., echo “trying to change the file” >> testfile1.html
delete each file
e.g., rm testfile1.html
File Permission Exercise
To test the ability to load a .html file in a browser, you need to set up a softlink (aka
symbolic link) under your public_html directory
cd
cd public_html
ln -s <original> <link name>
- creates a softlink (called link name), which points to the original subdirectory
e.g., ln –s ~kkhan/public_html/testfiles testdir
cd <link name> takes you to the original subdirectory
cd testdir
Now, in the browser (for example running on the pc) you can use the open file option
to test loading the .html files
If the file loaded successfully, then there is a brief text displayed from the file
Try loading one that definitely should work:
testdir8/testfile8.html