CONCEPT: The UNIX filesystem is heirarchical (resembling a tree structure). The tree is anchored at a place called the root, designated by a slash "/". Every item in the UNIX filesystem tree is either a file, or a directory. A directory is like a file folder. A directory can contain files, and other directories. A directory contained within another is called the child of the other. A directory in the filesystem tree may have many children, but it can only have one parent. A file can hold information, but cannot contain other files, or directories.

CONCEPT: To decribe a specific location in the filesystem heirarchy, you must specify a "path." The path to a location can be defined as an absolute path from the root anchor point, or as a relative path, starting from the current location. When specifying a path, you simply trace a route through the filesystem tree, listing the sequence of directories you pass through as you go from one point to another. Each directory listed in the sequence is separated by a slash.
UNIX provides the shorthand notation of "." to refer to the current location, and ".." to refer to the parent directory.
EXERCISE: Specify the absolute path to the directory named "jon" at the bottom of the tree diagram.
EXPLANATION: Since the absolute path must always begin at the root (/) directory, the path would be:
EXERCISE: Specify the relative path from the directory named "student" to the directory named "jon" in the tree diagram.
EXPLANATION: Starting from the student directory, we would first have to move up the filesystem tree (using the ".." notation) to the directory called "users" before we could descend to the directory called "jon". The path would be:
CONCEPT: UNIX supports access control. Every file and
directory has associated with it ownership, and access permissions.
Furthermore, one is able to specify those to whom the permissions
apply.
Permissions are defined as read, write, and execute. The read,
write, and execute permissions are referred to as r, w, and x,
respectively.
Those to whom the permissions apply are the user who owns the file,
those who are in the same group as the owner, and all others. The
user, group, and other permissions are referred to as u, g, and o,
respectively.
A short note on groups: UNIX allows users to be placed in
groups, so that the control of access is made simpler for
administrators.
The meaning of file and directory permissions
To see the permissions on a file, use the ls command, with the -l
option.
EXAMPLE: Execute the command
-rw-r--r-- 1 root sys 41002 Apr 17 12:05 /etc/passwd
The first 10 characters describe the access permissions. The first
dash indicates the type of file (d for directory, s for special file,
- for a regular file). The next three characters ("rw-") describe
the permissions of the owner of the file: read and write, but no
execute. The next three characters ("r--") describe the permissions
for those in the same group as the owner: read, no write, no execute.
The next three characters describe the permissions for all others:
read, no write, no execute.
UNIX allows you to set the permissions on files that you own. The
command to change the file permission mode is chmod. Chmod requires
you to specify the new permissions you want, and specify file or
directory you want the changes applied to.
To set file permissions, you may use to the "rwx" notation to
specify the type of permissions, and the "ugo" notation to specify
who the permissions apply to.
To define the kind of change you want to make to the permissions,
use the plus sign (+) to add a permission, the minus sign (-) to
remove a permission, and the equal sign (=) to set a permission
directly.
EXAMPLE: Type the command EXERCISE: Change the permissions on the .shrc file in your
home directory so that group and others have read permission only.
EXPLANATION: Typing the command To change your location in the filesystem heirarchy, use the cd
(change directory) command, followed by an argument defining where you
want to go. The argument can be either an absolute path to the
destination, or a relative path.
EXAMPLE: Type the command
If you type the cd command without an argument, the shell will place
you in your home directory.
EXERCISE: Type the command EXPLANATION: The "cd .." command should have moved you up
one level in the directory tree, because ".." is UNIX shorthand for
the parent directory. The result of the second "pwd" command should
be the same as the first, with the last directory in the path omitted.
The ls command allows you to see the contents of a directory, and to
view basic information (like size, ownership, and access permissions)
about files and directories. The ls command has numerous options, so
see the manual page on ls (type man ls) for a complete listing.
The ls command also accepts one or more arguments. The arguments can
be directories, or files.
EXAMPLE: Type the command
In the example, the "l" and "r" options of the ls command are
invoked together. Some commands permit you to group options in that
way, and some commands require the options to be named separately,
e.g., ls -l -r. The l option calls for a long output, and
the r option causes ls to operate recursively, moving down directory
trees.
The last part of the example, "/etc/i*", directs the ls command to
list files and directories in the /etc directory, that begin with the
letter i. The wildcard character, "*", matches any character(s).
EXERCISE: Type the command EXPLANATION: The shell responded by printing all the
entries in the /etc directory that start with the letter i, and end
with the letter g. The -m option causes the output to be streamed
into a single line. See the manual page for ls to get a complete
description of the ls command's options.
EXERCISE: Find the permissions on your home directory.
EXPLANATION: There are many ways to accomplish this. You
could type
CONCEPT: Text files are intended for direct viewing, and other
files are intended for computer interpretation.
The UNIX file command allows you to determine whether an unknown file
is in text format, suitable for direct viewing.
EXERCISE: Type the command EXPLANATION: The shell is a shared executable, indicating
that the file contains binary instructions to be executed by the
computer.
The cat command EXAMPLE: Send the contents of your .profile file to the
screen by typing
The more command EXAMPLE: Type
The head and tail commands EXAMPLE: Type
The tail command works like head, except that it shows the last lines
of of file.
EXAMPLE: Type
The UNIX command to copy a file or directory is cp. The basic cp
command syntax is cp source destination.
EXAMPLE: The command EXERCISE: Describe the permissions necessary to
successfully execute the command in the previous example.
EXPLANATION: To copy the .profile file, one must have read
permission on the file. To create the new file called pcopy, one must
have write permission in the directory where the file will be created.
The UNIX mv command moves files and directories. You can move a file
to a different location n the filesystem, or change the name by moving
the file within the current location.
EXAMPLE: The command
The rm command is used for removing files and directories. The syntax
of the rm command is rm filename. You may include many
filenames on the command line.
EXAMPLE: Remove the the shrccopy file that you placed in
your home directory in the section on moving files by typing
The UNIX mkdir command is used to make directories. The basic syntax
is mkdir directoryname. If you do not specify the place
where you want the directory created (by giving a path as part of the
directory name), the shell assumes that you want the new directory
placed within the current working directory.
EXAMPLE: Create a directory called foo within your home
directory by typing
EXERCISE: Create a directory called bar, within the directory
called foo, within your home directory.
EXPLANATION: Once the foo directory is created, you could
just type
The UNIX rmdir command removes a directory from the filesystem tree.
The rmdir command does not work unless the directory to be removed is
completely empty.
The rm command, used with the -r option can also be used to remove
directories. The rm -r command will first remove the contents of the
directory, and then remove the directory itself.
EXERCISE: Describe how to remove the "foo" directory you
created, using both rmdir, and rm with the -r option.
EXPLANATION: You could enter the commands
File and directory permissions
Viewing permissions
to view the information on the system password
database. The output should look similar to this:
Setting permissions
to change the file permissions on the file .shrc, in
your home directory. Specifically, you are specifying group read
access and write access, with no execute access.
would accomplish the task.
Changing Directories
In UNIX, your location in the
filesystem heirarchy is known as your "current working directory."
When you log in, you are automatically placed in your "home
directory." To see where you are, type the command
which stands for "print working
directory."
to
go to the /tmp directory. You can type
to
confirm that you're actually there.
and
note the result. Then type
to the shell.
Type
again to see where you ended up.
Listing the contents of a directory
to the UNIX shell.
to the shell. How did the shell respond, and why?
to get to your home directory, and
then type Viewing the contents of a file
to see what kind of file the shell is.
The cat command concatenates files and sends them to the screen. You
can specify one or more files as arguments. Cat makes no attempt to
format the text in any way, and long output may scroll off the screen
before you can read it.
to the shell.
The tilde character (~) is UNIX shorthand for your home directory.
The more command displays a text file, one screenful at a time. You
can scroll forward a line at a time by pressing the return key, or a
screenful at a time by pressing the spacebar. You can quit at any
time by pressing the q key.
to the
shell. Scroll down by pressing return, and by pressing the spacebar.
Stop the more command from displaying the rest of the file by typing
q.
The head command allows you to see the top part of a file. You may
specify the number of lines you want, or default to ten lines.
to see
the first fifteen lines of the /etc/rc file.
to see the
last ten lines of the file /etc/rc. Because we did not specify the
number of lines as an option, the tail command defaulted to ten lines.
Copying files and directories
makes a copy of your .profile file, and stores it in
a file called "pcopy" in your home directory.
Moving and renaming files
takes the pcopy file you created in the cp exercise,
and renames it "qcopy".
Removing files
Creating a directory
Alternately, you could
type
In the second solution,
two UNIX commands are given, separated by a semicolon. The first part
of the command makes foo the current working directory. The second
part of the command creates the bar directory in the current working
directory.
Removing a directory
to accomplish the
task with the rmdir command. Note that you have to rmdir the bar
subdirectory bfore you can rmdir the foo directory. Alternately, you
could remove the foo directory with the command