Files and Directories
PAGEFLOP
FORWARD
SELECTOR
SELAGAIN
WRONGSEL
YOUR SELECTION IS NOT IN THE 0 - #SELIMIT RANGE Please try again
AANVANG
Copyright CourseWare Technologies, Inc., 1985-88
Lesson - 4
FILES AND DIRECTORIES
MENU
Files and Directories|Topics to Learn|4-0|8,54
# Topic
--- -------
1 - The Hierarchical File System
2 - Navigating Through the File System
3 - Access Permissions and How to Change Them
4 - UNIX File Types
5 - Lesson Review
0 - Return to the Main Menu
TOPIC1
The Hierarchical File System
P1
Files and Directories|Hierarchical File System|4-1.1| 11 , 52
The file system is a uniform set of
directories and files arranged in a tree-like,
hierarchical structure.
Files are grouped into directories and
the directories are organized into a hierarchy.
At the top of the hierarchy is a special
directory called root, with the name / .
P2
Files and Directories|Hierarchical File System|4-1.2| 12 , 47
A pathname is the complete name of a
directory or a file.
A pathname traces a path through the file
system to the desired file.
The pwd command prints the full pathname
of your current working directory. It provides
a list of all of the directories on the path,
separated by slashes (/).
P3
Files and Directories|Hierarchical File System|4-1.3| 8 , 45
If your login name is ann, when you type pwd,
you will see the full pathname of your home
:directory:
/usr2/ann
Remember, your home directory is the one you
are automatically placed in when you log on.
TOPIC2
Navigating through the File System
P4
Files and Directories|Navigating Through the File System|4-2.1|5,58
Remember, you can change to a different directory
at any time. Any directory that you change to is called
your current working directory. If you do not change
directories after you log on, then your home directory
is your current working directory.
P5
Files and Directories|Navigating Through the File System|4-2.2| 7 , 48
You can move to another directory with a
command called cd (for change directory).
The syntax for the cd command is:
cd fullpathname of new directory
P6
Files and Directories|Navigating Through the File System|4-2.3| 7 , 57
If you want to return to your home directory using
the cd command, you could type:
cd /usr2/ann
or you could simply type cd, because when the cd command
has no arguments, it returns you to your home directory.
P7
Files and Directories|Navigating Through the File System|4-2.4|4,46
The directory in which your current directory
is placed is called a parent directory. The
parent directory for /usr2/ann is /usr2 because
it is one level higher on the tree.
P8
Files and Directories|Navigating Through the File System|4-2.5| 13 , 60
A shorthand name for a parent directory is .. .
You can use this shorthand notation with the cd command.
If your current directory is /usr2/ann and you
wish to change to your parent directory (/usr2) you
can type either:
cd /usr2 or cd ..
Note that in this example, the parent directory and
the home directory are the same. If you are more than
two levels down in the tree, they will be different.
P9
Files and Directories|Navigating Through the File System|4-2.6| 8 , 51
You can use the .. shorthand to go up more than one
directory at time. For example, if you are in
/usr2/ann, the command:
cd ../..
will take you first to your parent directory, then
to the directory above that, the root directory, / .
P10
Files and Directories|Navigating Through the File System|4-2.7| 10 , 52
Absolute pathnames are specified by
starting the path at the root directory: / .
For example,
cd /usr2/bob/memos/to_mary
Pathnames that start from the current
working directory instead of the root directory
are called relative pathnames.
P11
Files and Directories|Navigating Through the File System|4-2.8| 9 , 57
If Bob is in the directory /usr2/bob/memos and he wanted
to leave his memos directory and go to a directory called
letters in his home directory he could type:
cd ../letters
Because he didn't start with a / , it is assumed that
he is using a relative pathname. The absolute pathname
would be /usr2/bob/letters.
P12
Files and Directories|Navigating Through the File System|4-2.9| 6 , 56
The mkdir (for make directory) command allows you to
create a new subdirectory in your current working
directory. If you are in the home directory, /usr2/ann,
and wish to make a new directory called report, you can
type:
mkdir report
TOPIC3
Access Permissions and How to Change Them
P13
Files and Directories|Access Permissions|4-3.1| 9 , 50
The owner of a file can control which users have
permission to access the file. There are three
types of users on the system:
* the owner of the file,
* a member of the group to which the owner
belongs,
* and any other person not in the owner's
group.
P14
Files and Directories|Access Permissions|4-3.2| 11 , 54
There are three different types of permissions which
determine what kinds of things can be done with a file
(by the owner or anyone else):
* the contents of the file can be looked at
(read permission),
* the contents of the file can be changed
(write permission), and
* the file can be used as an executable or
"runable" UNIX system command
(execute permission).
P15
Files and Directories|Access Permissions|4-3.3| 17 , 65
When you combine the three types of users and the three types of
permissions, you get 9 possible ways that a file can be accessed:
The owner can:
read the file
write to the file
execute the file
A member of the owner's group can:
read the file
write to the file
execute the file
Any other person with an account can:
read the file
write to the file
execute the file
P16
Files and Directories|Access Permissions|4-3.4| 10 , 64
These nine permissions are usually written as:
rwxrwxrwx
where the first 3 letters refer to the permission of the owner,
the second 3 letters refer to the permission of the owner's group,
and the last 3 letters refer to the permission of all others.
These nine permissions are collectively called the mode of
a file.
P17
Files and Directories|Access Permissions|4-3.5| 4 , 50
The -l option to the ls command will give you a
long listing of each file in a directory. This
listing will include the access permissions among
other things.
P18
Files and Directories|Access Permissions|4-3.6| 7 , 61
For example, the ls -l command might produce the following
output:
-rw-rw-r-- 1 ann admin 6329 Nov 14 17:07 report
-rw-rw-r-- 1 ann admin 3677 Nov 14 17:07 letter
-rw-r--r-- 1 ann admin 3677 Nov 14 17:07 addresses
-rwxrwxrwx 1 ann admin 4127 Nov 14 17:04 cprogram
P19
Files and Directories|Access Permissions|4-3.7| 9 ,56
A missing letter is called a protection and is indicated
by a dash (-).
A permission of rw-rw-r-- means that:
- the owner can read and write to the file (rw-),
- a member of the owners group can read and write
to the file (rw-),
- all others can only read the file (r--).
P20
Files and Directories|Access Permissions|4-3.8| 7 , 50
The chmod command allows you to change the mode of
a file if you are the owner. The syntax is:
chmod mode filename
The mode requires a 3 digit number according to the
following scheme:
P21
Files and Directories|Access Permissions|4-3.9| 12 , 60
To figure out the mode of a file, each letter is assigned a
number value:
an r is 4
a w is 2
an x is 1
For example, rw-rw-r-- would be:
owner group other
r w - r w - r - -
4 2 0 4 2 0 4 0 0
P22
Files and Directories|Access Permissions|4-3.10| 10 , 61
You have to add up the three numbers for each type of user:
owner group other
r w - r w - r - -
4+2+0 4+2+0 4+0+0
6 6 4
So the mode for rw-rw-r-- is 664. This allows the owner and
any member of her group to read and write to the file. All
other users can only read the file.
P23
Files and Directories|Access Permissions|4-3.11| 12 , 51
To change the mode of a file called private so that
only you can read it or write to it, you would need
to create the following permissions:
you group others
rw- --- ---
420 000 000
6 0 0
The command would be:
chmod 600 private
TOPIC4
UNIX File Types
P24
Files and Directories|UNIX File Types|4-4.1| 8 , 50
Because different files are used for different
purposes, UNIX files are classified into 5 types:
1. Ordinary Files
2. Directory Files
3. Character Special Files
4. Block Special Files
5. FIFO Files
P25
Files and Directories|UNIX File Types|4-4.2|15,69
Ordinary files are executable programs and various
system and user created data storage files.
Directory files are used by the system to maintain
the hierarchical file structure.
Character special files are used by the system for serial
communication with serial peripherals.
Block special files are used by the system for parallel
communication with parallel peripherals.
FIFO files (First In First Out) are named pipes
and are used in UNIX pipe processes.
(You'll learn about these later.)
P26
Files and Directories|UNIX File Types|4-4.3| 13 , 53
The first character of the file protection descriptor (as
seen when using the command ls -l) indicates the file
type. For example:
- - Ordinary
d - Directory
c - Character Type
b - Block Type
p - FIFO
TOPIC5
Lesson Review