Tutorial -- UNIX Basics
Goal:
Filesystem structure
A filesystem is literally a hierarchical structure in which files are kept.
The fundamental building blocks of a filesystem are directories and files.
A directory is an element that (typically) cannot hold any data itself, but
is merely a repository for files and other directories. The concept of a "Folder"
that is used in both Microsoft Windows and in the MacOS is a graphical representation
of a directory - a folder can contain both files and other folders. In contrast,
a file is a structure that can be used to store data, but cannot itself contain
other files and/or directories. (*There are exceptions)
In a UNIX filesystem, all directories are connected to the root directory,
denoted as a single forward-slash (/). This is fundamentally different from
the method used in Windows, where each filesystem is given a "drive letter".
Instead, in UNIX-based systems a new filesystem is attached to an existing
filesystem at a "mount point". A mount point is a directory that is used as
a reference into the other filesystem.
When describing a files location there are two conventions. The first is
to use a completely defined path to the file, beginning with the root directory
(e.g., /usr/bin/ls). The other is to give a location relative to the directory
you are currently "in". To assess which directory you are in, you may use
the 'pwd' [LINK] command. This prints out which directory you are currently
in, referred to as your current working directory. So if you are in
the /usr directory, you could refer to the ls file located at /usr/bin/ls
as bin/ls. And if you were in the /usr/bin directory, you could refer to the
file directly as ls. In this instance, to specifically refer to the /usr/bin/ls
file when you are already in the /usr/bin directory, you
could also use a "shortcut" reference to your current directory. This reference
is a single period (.) often referred to as "dot" or "dot directory". There
is an additional "shortcut" reference to the directory in which your current
working directory can be found. This reference is denoted with two periods
(..) and will be referred to as "dot-dot".
To see how this works, we'll use the example of a file whose complete path
name is /usr/bin/ls. If your current working directory was /usr/bin
, then the .. directory points to /usr. And if your current working
directory was /usr, then the .. directory points to /. So what is pointed
to by the .. shortcut in the root directory? This is one of the special cases
in a filesystem hierarchy. The root directory's .. directory usually points
to itself.
Now that we have a basic understanding of a filesystem, there are some conventions
for file locations that are important to know.
/
/bin /etc
/home /lib /mnt /sbin
/usr /var
/usr/bin /usr/lib /usr/man
FIGURE 1
A partial listing of a filesystem can be seen in Figure 1. These directories
almost always exist in a UNIX system, and are commonly used to store specific
types of data. An example of the types of data can be seen in TABLE 1.
/bin frequently
used binaries required for basic system operations.
/etc configuration
files
/home where user
data is stored
/lib required
libraries for basic system operation
/mnt often
used as a location to mount additional filesystems
/sbin system binaries
required for maintainence, often cannot
be run by "normal" users
/usr contains
a hierachy of directories for more complete
system use
/var additional
configuration files and logging
TABLE 1
For example, the configuration files in /etc specify (i) who can log in
to the computer, (ii) what programs/services are run by default, (iii) what
network address is assigned to the computer, (iv) jobs to be run periodically,
etc. While the filesystem structure presented here is in common usage across
most UNIX-based filesystems, in general there is no guaranteed structure.
Indeed, the /home directory is often substituted with a separate directory
hierachy used to contain user's data.
In Linux-based systems, most of the log files are kept in the {\tt /var/log}
directory. A common method of distributing messages for general system messages
to be logged into /var/log/messages, log-in and authentication messages to
be logged in /var/log/secure, and so on. However, each distribution tends
to have slight variations on the default configuration of message logging.
In addition, the exact manner of how messages are logged are configurable
(see /etc/syslog.conf).
Accounts
An important concept to recall when dealing with UNIX, especially when coming
from the Windows and Macintosh oriented world, is that any user of the computer
has to have an owner. This is an important distinction from both Windows and
Macintosh, although Windows is slowing moving towards the concept (and requirement?)
of user accounts. The reason the concept of user accounts is necessary is
due to the power (and therefore the complexity) of a multiple processing
operating system (e.g., all UNIX variants).
Imagine a set of processes (programs) all running concurrently.
User accounts allow multiple people to run their own programs at the same
time, and the keep the data separate. This becomes important because
there are now certain operations that are not allowed to just any user. Why
is this important? All of the sudden, you have a computer connected to the
internet 24 hours a day, allowing connections to be
made to it from anywhere in the world. How do you allow one user (Alice)
to log in from her computer at home while not allowing everyone else? This
can only be done through an authentication mechanism. Currently, we use a
login and password pair. The login is used identify who is logging in. The
problem then becomes that a login is not a secret. Everyone on that system
knows about the account, and the is the "name" with which email is marked.
(For an obvious example, my login on most machines is {\tt tscheetz},
and my email address is {\tt tscheetz\@eng.uiowa.edu}). Clearly the login
is not secure in and of itself. That's where the password comes in, it's a
"secret" that should be known only to the account's owner.
Account attributes
So what types of attributes does a user account have besides the login and
password? For starters, a home account is specified, which is a directory
that is owned by the user, and into which files can be written. In addition,
a numeric user ID (UID) and group ID (GID) are also associated with each user
account. In general, there is a unique assignment between the UID and a user,
although there are instances where UID sharing among accounts may be appropriate.
For further discussion on the usefulness of UIDs and GIDs, see the section
on permissions (Section~\ref{PERM}). Also the shell (command line interpreter)
started by default when the user logs in is also an account attribute.
What types of accounts are there?
There is one
very special account that must be present in
all variants of the UNIX operating system. This is the {\bf root} account,
which has unlimited access\footnote{There are several realistic limits to
the functionality of the root account (ACLs, root\_squash on NFS mounts).}
to all files and processes within the operating system. The root account
is the account used for system administration events (e.g., configuration
and account management). However, it is important for security reasons that
the root account is not used by a user for his or her "every day" use. Therefore
every user of a system should have their own account.
Account Management
Most UNIX systems come with a program to assist in adding user accounts.
For Linux this program is called {\tt useradd}, for Solaris this program is
called {\tt add\_user}. These programs allow specification of all of the attributes
associated with accounts. For example, to add an account for Alice, with
login {\tt alice}, home directory {\tt /home/alice}, using default/incrementally
assigned for the remainder of attributes the following command would be used.
useradd -d /home/alice -m alice
Here, the {\tt -m} flag is used to create the home directory if it doesn't
exist. This is important, as unless this flag has been specified, a user would
not have a home account, which can cause extensive problems.
How to remove an account?
TBA
Processes & Daemons
What is a process?
How to processes get started?
Where are the system processes started from?
Process management (starting and stopping processes)
Environment Variables
Commands
(set/setenv (tcsh), export (bash), stty)
Variables
(PATH, DISPLAY, LANG, etc.)
terminal settings
(stty erase)
Shells
The shell is the essential command-line interface (CLI). It provdies the
interpreter, in which all commands are executed.
sh - Bourne Shell
The Bourne shell (sh) is the primary sheel used to execute system scripts.
It is not a typical user shell as it does not implement many of the user
friendly command-line shortcuts such as auto-completion of file names.
bash - Bourne Again Shell
The bash shell is one of the most flexible shells, and is the default shell
for the root account. On some systems and distributions, the root account
shell must be bash.
csh - C Shell
tcsh - T*'s C Shell
Permissions
What are permissions for?
Permissions allow specification of which users can access files. Standard
permissions available are (1) read, (2) write, and (3) execute. There are
three sets of permissions for every file and directory - for the owner of
the file, the group associated with the file, and for all users. Groups are
a method for compactly referring to a set of users.
How can I see what permisstions I have on a file (or directory of files)
?
By default, list the files (e.g., with 'ls') does not show the permissions
associated with each file. To see a files permissions you nneed to use 'ls
-l' or 'ls -lg'. The command 'ls -l' shows the permissions associated for
each file, but 'ls -lg' also shows the group associated with each file.
[DESCRIBE FORMAT]
How can I change permissions on a file?
To change permissions, the chmod command is used. The arguments to chmod
are either [ugo][+-][rwx], or ###. The latter format is known as octal format,
in which the read, write and execute options are compacted into a single
digit from 0 to 7 for each of the user, group and all.
read -> 4
write -> 2
execute -> 1
read + write -> 6
read-only -> 4
write-only -> 2
read + write + execute -> 7
no permissions -> 0
So to set full permissions (read, write and execute) for the owner, group
and all on the file foo.pl, the command 'chmod 777 foo.pl' would be used.
How can I change the default permissions assigned to my files?
To set the default permissions for a newly created file the command/environment
variable umask is used. Here the values passed are the complement of the
default permissions to be assigned (in octal format). Thus, to set default
permissions to read and write for the user only would be 077. Note the lack
of execute restriction for the user. The default permissions won't be set
for execute unless the application creating the file assigns them.
X-windows
1. XFree86
Sun vs. Linux
2. How to start (startx/xinit)
3. .xinitrc
4. xrdb
5. xmodmap
Last Updated: March 1,
2002 by Todd Scheetz