Title: Announcements:
1- Announcements
- Instructor Yifeng Zhu
- Email yzhu_at_cse.unl.edu
- Office 501 Building, Room 2, Cubic 2.2
- Office Hour Monday 400-500, or by appointment
- Phone 472-0820
- Grader Olga Komina
- Email okomina_at_cse.unl.edu
- Office 501 Building, Room 5, Cubic 5.7
- Office Hour
- Phone 472-5029
- For those who got new accounts, please register.
Otherwise, your new accounts will be closed after
two weeks. - A typo on Syllabus web course link
http//cse.unl.edu/yzhu/cs251 - Quiz drop only one. (two zeros, only one to be
dropped)
2Chapter 2 Exploring the UNIX File System
3Understanding 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
4Understanding 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 systems way of
organizing files on mass storage devices such as
hard and floppy disks
5Unix file system structure
- The file system is a hierarchical structure
resembling a rooted tree, anchored at the root
(/)
6Unix 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
7Absolute 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
8Navigating 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
9Navigating the File System
- cd ltdirgt change to ltdirgt
- 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
10Using 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
11Tilda () 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 persons home directory cd yzhu
12Creating Deleting files
- cp copy file or directory
- mv move file or directory
- mkdir create a directory
- rmdir delete a directory
- rm delete a file
- rm -r delete recursively
- rm -rf force recursive delete
13Copying 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
14Renaming 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.
15Removing 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
16Unix 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 files 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 owners permissions
17Unix 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.
18View Permissions
ls l /etc/passwd -rw-r--r-- 1 root root
1369 Apr 30 2003 /etc/passwd ls l
/bin/ls -rwxr-xr-x 1 root root
46888 Jan 19 2003 /bin/ls
owner
group
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.
19File Permission Specifiers
20Examples 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
21Examples 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
22Changing Permissions
- chmod ugoa(/-)rwx ltdirgt
- Where
- u user, g group, o others, a all
- add permission, - remove
- To make a directory readable by others
- chmod gorx ltdirgt
23Making a web page
- 1. Create the directory
- cd (or cd )
- mkdir public_html
- 2. Set the Unix permissions
- chmod gox (or chmod ax )
- chmod gorx public_html (or chmod ax
public_html) - 3. Create the index.html file
- cd /public_html
- cp yzhu/public_html/cs251/example.html
index.html - chmod gorx index.html
- Feel free to edit or substitute your own html
file(s).
24Chapter 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 systems 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
25Chapter 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