Document 7907014

Download Report

Transcript Document 7907014

Announcements:
1. Instructor: Yifeng Zhu
Email: [email protected]
Office: 501 Building, Room 2, Cubic 2.2
Office Hour: Monday 4:00-5:00, or by appointment
Phone: 472-0820
2. Grader: Olga Komina
Email: [email protected]
Office: 501 Building, Room 5, Cubic 5.7
Office Hour:
Phone: 472-5029
3. For those who got new accounts, please register.
Otherwise, your new accounts will be closed after two
weeks.
4. A typo on Syllabus: web course link:
http://cse.unl.edu/~yzhu/cs251
5. Quiz: drop only one. (two zeros, only one to be dropped)
Chapter 2: Exploring the UNIX File
System
File and File Systems
Understanding Files and Directories:
Objectives
• After studying this lesson, you
should be able to:
– File system structure
– Navigating, creating and deleting…
– Unix permissions
– Build your own personal web
Understanding the UNIX File System
• In UNIX, a file is the basic component for
data storage
• UNIX considers everything it interacts with
as a file, even attached devices such as
monitors
• A file system is the UNIX system’s way of
organizing files on mass storage devices
such as hard and floppy disks
Unix file system structure
• The file system is a hierarchical
structure resembling a rooted tree,
anchored at the root (“/”):
/
bin
bin
local
usr
games
etc
users
include
lib
lib
Unix file system structure
• Every item in the file system is a file (or a
link).
• Directories can contain file and other
directories (called subdirectories). The
subdirectory is considered as the child of
the parent directory
• Each directory may have only one parent.
• A directory is a special kind of file that can
contain other files and directories
Absolute & Relative Paths
• To describe an object in the file
system you specify a path.
• Paths are either absolute, beginning
at the root level:
/usr/local/bin/howto
• Or they are relative to the current
directory:
../stuff/morestuff/afile
Navigating the File System Continued
• Any time the \ symbol is the first character
in a path, it stands for the root directory
• A relative path takes a shorter journey
• You can enter the relative path to begin at
your current working directory and
proceed from there
Navigating the File System
cd <dir>
change to <dir>
cd ..
change to parent dir
pwd
print current directory
ls
list directory contents
ls -l
long listing
ls -a
list all files
ls -al
long listing, all files
Using Dot and Dot Dot Addressing
Techniques
• UNIX interprets a single dot character to
mean the current directory, and dot dot
(two consecutive dots) to mean the parent
directory
• cd . - keeps you in the current directory
• cd .. - returns the user to their home
directory
Tilda (~) directory
• The tilda (~) represents your home directory.
• It is a short cut. It means the same thing as
/home/user_name
• Example:
– Enter your home directory: cd ~
– Enter another person’s home directory: cd ~yzhu
Creating & Deleting files
cp
mv
mkdir
rmdir
rm
rm -r
rm -rf
copy file or directory
move file or directory
create a directory
delete a directory
delete a file
delete recursively
force recursive delete
Copying files
cp copy file or directory
• syntax: cp [options] source-file destination-file
• source-file: name and path of file to be copied
• destination-file: name and path of resulting copy of the file
• options: are optional; not required
• Common options:
– -i : interactive copy; prompts before overwriting an
existing file
– -r : recursive copy; copies the entire directory structure
from the top down and recreates it at destination
• Examples:
– cp /etc/passwd .
– cp –i /etc/passwd ~
– cp /etc/passwd ~/fileb
– cp -r /etc/pcmcia ~
Renaming files
mv move file or directory
• Better name could be the rename
command.
• Changes the name of one file to
another.
• Syntax: mv [options] [old file name]
[new file name]
• Note, if [new file name] is a directory,
you will move [old file name] to that
directory and keep the original name.
Removing files
rm remove file or directory
• Deletes the specified file or files.
• This is destructive!
• They are gone!
• They cannot be retrieved!!!
• Syntax: rm [options] [file name]
• Note: this does not generally work
with directories.
– rm –r [directory name]
Unix File Permissions
• Because UNIX is a multi-user system, users
can set permissions for files they own so that
others can read, write, or execute their files
• A file’s owner is the person who created it
• The permissions the owner sets are listed as
part of the file description
• The first section of file permission specifiers
indicates the owner’s permissions
Unix File Permissions
• Each file and directory has permissions that
support access control.
• Permissions are defined as:
read (‘r’) – view contents
write (‘w’) – change contents
execute (‘x’) – run the file or change to the
directory
• Permissions are defined in three sets, for the
owner, group, and all others.
• Directories must be executable to be accessed.
View Permissions
$ ls –l /etc/passwd
-rw-r--r-1 root
$ ls –l /bin/ls
-rwxr-xr-x
1 root
owner
root
1369 Apr 30
root
46888 Jan 19
group
2003 /etc/passwd
2003 /bin/ls*
size creation date
permissions
1st character: type, ‘-’ for file, ‘d’ directory, ‘s’ special, ‘l’ link
Next three are read, write, execute for owner
Then, next three for group, and next three for all others.
Character means permission granted, ‘-’ means denied.
File Permission Specifiers
R
User (u)
Group (g)
All (a)
W
X
Examples: file permissions
-rw------Only owner can read and write
-rwxrwxrwx
Everyone can read, write and execute (and delete)
(not very common!)
-rw-r--r-Everyone can read, but only owner can write
Examples: directory permissions
drwx-----Only owner can view, cd into, and delete
drwxrwx--Owner and group can view, write, etc.
drwxr-xr-x
Everyone can cd into but only owner can
modify
Changing Permissions
$ chmod [ugoa(+/-)rwx] <dir>
Where
• u = user, g = group, o = others, a = all;
• + = add permission, - = remove
To make a directory readable by others:
$ chmod go+rx <dir>
Making a web page
1. Create the directory:
$ cd (or: cd ~)
$ mkdir public_html
2. Set the Unix permissions:
$ chmod go+x ~ (or: chmod a+x ~)
$ chmod go+rx public_html (or: chmod a+x public_html)
3. Create the index.html file:
$ cd ~/public_html
$ cp ~yzhu/public_html/cs251/example.html index.html
$ chmod go+rx index.html
Feel free to edit or substitute your own html file(s).
Chapter Summary
• In UNIX, a file is the basic component for data
storage. UNIX considers everything to be a file,
even attached devices
• A file system is the UNIX system’s way of
organizing files on mass storage devices such
as hard and floppy disks
• Every file can be located by using a correct and
unique pathname, that is, a listing of names of
directories leading to a particular file
Chapter Summary Continued
• The standard tree structure starts with the
root (/) directory, which serves as the
foundation for a nested group of other
directories and subdirectories
• A path, as defined in UNIX, serves as a map
to access any file on the system. Special
path( . (the directory itself), .. (the parent
directory), ~ (the home directory))
• You can use the chmod command to set
permissions for files that you own
• Commands: ls, cd, pwd, cp, rm, mkdir, rmdir