Week 2 - Filesystems

Week 2

The Filesystem
  • The root hierarchy
  • Navigation
  • Permissions
  • More shell commands
  • Text editors

Miscellaneous Info

Handouts

  • Most of this week's notes are included in the handouts. Make sure to read them closely, especially the examples.

Pronunciation

  • Pronunciation of punctuation can be troublesome when
    describing shell command syntax, so the following is a list of the
    common names (most common first):
  • ! = bang
  • * = splat, star
  • @ = at, strudel
  • . = dot, point, period
  • # = hash, crunch, pound, pound sign
  • ~ = twiddle, tilde
  • | = pipe, bar
  • - = dash, minus, hyphen
  • _ = underscore
  • / = slash
  • \ = backslash, escape
  • & = amp, ampersand
  • $ = dollar
  • % = percent
  • ^ = caret, hat, control
  • ? = question
  • ( = prance, parens, parenthesis
  • [ = bracket, square bracket
  • { = brace, curly
  • ' = quote
  • ` = back quote
  • " = double quote

Shell Tips

  • Ctrl+C breaks (stops) a running program (eventually/usually)
  • Ctrl+\ stops a running program (use if Ctrl+C didn't work)
  • Ctrl+D
    signals End of File (EOF). If you run the cat program without any
    parameters, it will expect input from the keyboard instead. Use Ctrl+D
    to exit.
  • Ctrl+S suspends output to screen. Use Ctrl+Q to restart.
  • Ctrl+U erase command line
  • Ctrl+Z suspends the current job. Use fg to restart.
  • Use
    the TAB key to autocomplete file names when typing commands. Hit TAB
    again to show list of possible matches if it beeps the first time.
  • Use the up and down arrows to go back and forward in the command line history. Return will execute the command again.

vi Editor

  • Seems like stone age tool, but useful for 3 reasons: fits on
    a floppy, comes with every UNIX/Linux distro you can think of, runs
    without GUI so it can be used remotely through telnet or ssh (with less
    keyboard map fiddling as usually in the case of Emacs)
  • Actually quite powerful once you're used to it: Running Linux book was written using vi (and Emacs).
  • At the very least, you should be able to open a file, make simple additions or changes, and save the file again using vi.


vi Editor Quick Reference


vi Basics

Type vi at the shell prompt to launch the vi editor.
You can also specify a file to load on the command line.
In vi parlance, the onscreen text is called the "buffer", just as "document" is used in most GUI word processors.
Unlike most any editor you're likely used to, vi has "modes" as described below.
You'll find that you switch back and forth between modes frequently.



Consult
Learning the vi Editor
to more fully embrace the vi experience.

Modes

ModeDescription
Command
Keystrokes are interpreted as commands for movement, entry into the
Insert or Replace mode, deletions, search, replace, file manipulation,
and so on. There are no indications that vi is in Command Mode. Press
ESC once or twice until the terminal beeps. The beep means Command Mode
(sometimes called "Beep Mode").
Insert, Replace
Keystrokes are inserted (Insert Mode) into the buffer, or replace existing buffer text (Replace Mode).
Either --INSERT-- or --REPLACE-- will appear at the bottom of the screen as a reminder of the current mode.
Press ESC to return to Command Mode.

Commands
Commands are keystrokes entered while in Command Mode.
The case of the command is significant.
Some commands can be executed more than once by first typing the number of repetitions.
There are many, many more commands in vi than listed here.
Insert CommandsDescriptionExamples
i, aEnter Insert Mode and begin inserting text before, or after the cursor, respectively. 
I, AEnter Insert Mode and begin inserting text at the beginning, or end of the current line, respectively. 
o, OEnter Insert Mode and begin inserting text on a new blank line inserted below, or above the current line, respectively. 
rRemain in Command Mode but replace the character under the cursor with the next keystroke.rQ replace the character under the cursor with the character Q
REnter Replace Mode and begin replacing text at the current cursor position. 
cwDelete the word to the right of the cursor, and enter Insert Mode.3cw delete the 3 words to the right of the cursor and enter Insert Mode
ccDelete the current line, and enter Insert Mode. 
ESCReturn to Command Mode. 
Movement CommandsDescriptionExamples
h, j, k, lMove
the cursor one position left, down, up, or right, respectively. On most
terminals, the keyboard arrow keys will also work, even in Insert Mode.
j move one line down,
13l move thirteen characters to the right
w, bMove the cursor one word forward, or backward respectively. Use capital W or B to move by word, including punctuation.4w move 4 words forward,
3B move 3 words backward treating punctuation as part of the words
eMove the cursor to the end of the word. Use capital E to end of word, including punctuation. 
0, $Move the cursor to the first or last position of the current line, respectively. 
GMove to the specified line number in the buffer. If no line number is given, move to the end of the buffer.
1G move to the beginning of the buffer,

13G move to 13th line of the buffer,

G move to the end of the buffer
Ctrl+f, Ctrl+bScroll
forward, or backward one screen, respectively. On most terminals, the
keyboard PageUp and PageDown keys will also work, even in Insert Mode.

3Ctrl+b scroll up 3 screens
Ctrl+gDisplay the current line number and other buffer information at the bottom of the screen. 
Ctrl+lRedraw the screen without changing anything. This may be necessary if the terminal displays a message on the vi screen. 
Editing CommandsDescriptionExamples
x, XDelete character under, or before the cursor, respectively. The deleted text can be restored with the p command.5X delete the five characters before the cursor
dwDelete one word to the right of the cursor. The deleted text can be restored with the p command.6dw delete the 6 words to the right of the cursor
ddDelete the current line. The deleted text can be restored with the p command.10dd delete the next 10 lines, starting with the current line
DDelete to the end of the line. The deleted text can be restored with the p command. 
p, PPut deleted text after, or before the cursor, respectively. 
ywYank (copy) the word to the right of the cursor. The yanked text can be restored with the p command.2yB yank the two previous words, including punctuation
yyYank (copy) the current line. The yanked text can be restored with the p command.4yy yank the next 4 lines, starting with the current line
JJoin the current line with the following line. 
uUndo the last edit command. 
.Repeat the last edit command. 
Search CommandsDescriptionExamples
/pattern,
?pattern

Search forward, or backward for pattern respectively.
Type Return to begin the search.
The pattern can be a text fragment or a regular expression.
/root search forward for "root"
?T[io]m search backward for "Tim" or "Tom"
n, NRepeat last search in same, or different direction, respectively. 
:%s/find_pattern/
replace_pattern/g

Globally replace find_pattern with replace_pattern in the buffer.
Type Return to begin the replacement.
Either pattern may be a text fragment or a regular expression.
:%s/usr/user/g replace every occurrance of "usr" with "user"
File CommandsDescriptionExamples
:wWrite (save) the buffer to the file on disk. 
:wqWrite (save) the buffer and quit vi. 
:x, ZZWrite (save) the buffer, if changes have been made, and quit vi. ZZ is a handy shortcut. 
:q!Quit vi without saving any changes, even if the buffer has been modified. 
:e!Restore the buffer to the version at the time of the last write (save). 






Linux Directory Structure



The various distributions of Linux or UNIX tend to use slightly
different directory structures, or organize files into different
locations.
The following structure is typical of most Linux distributions, and Red
Hat in particular.

Linux uses the term "directory" instead of "folder" as is preferred by the Macintosh and recent versions of Windows.
PathDescription
/
The root directory. Don't confuse this with the root user directory (/root).
The parent directory (..) of / is / itself.
/binEssential user commands, such as ls or bash.
/bootLocation of the kernel itself, as well as the boot manager (e.g. LILO or GRUB).
/dev
Files that represent hardware devices.
For instance /dev/hda2 corresponds to the second partition of the first IDE hard disk,
and /dev/fd0 represents the first floppy drive.
A special device, /dev/null, is like a black hole:
anything that is copied or streamed to /dev/null (also known as the "bit bucket") disappears forever.
Another special device, /dev/zero, is like the opposite: it spews out an infinite stream of zeros (technically, ASCII NUL).
There are usually many more files in this directory than there are hardware devices installed.
You'll rarely need to work directly with this directory.
/etcSystem configuration files. Similar in concept to Windows' Registry.
/etc/rc.dThe hierarchy for startup configuration scripts.
/etc/rc.d/init.dStartup configuration scripts.
/etc/rc.d/rcN.d
Runlevel directories. Each of the rcN.d directories corresponds to runlevel N.
The scripts in each directory (typically links to the scripts in /etc/rc.d/init.d) specify which services should start,
or stop, for that particular runlevel, and in which order.
/home
Home directories for user accounts (other than the root user).
Each user's directory will be directly beneath this directory: /home/user_name.
/lib
System libraries shared by various programs.
These library files are similar in intent to Windows' DLL files.
The /lib/modules/kernel_version directory contains the kernel modules, such as device drivers.
/mnt
The preferred location of temporarily-mounted device filesystems, such as the floppy drive (/mnt/floppy) or the CDROM
(/mnt/cdrom)
drive. Depending on system settings, these device filesystems may be
automatically mounted when a disk is inserted into the drive, or you
may have to mount themselves using the mount command.
/proc
The mount point for a virtual filesystem that contains files and
directories that represent current system settings and statistics. For
instance, /proc/meminfo shows the current status of the system memory,
and /proc/version displays the current kernel version.
There are also subdirectories for each of the running processes, identified by the process ID (pid) numbers.
/rootThe root user directory.
/sbinEssential privileged commands, usable only by the root user, such as shutdown.
/tmpTemporary files used by the system or users. Don't store important files in this directory as they may be erased without notice.
/usr
The primary hierarchy for programs, data, and documentation on the system.
The /usr directory may actually be located on a separate system, but accessed remotely.
Therefore the /bin and /sbin directories must contain all of the utilities necessary to
launch the system before any network connections are made.
/usr/binThe bulk of the user commands.
/usr/local
Programs, data, and documentation installed locally on this system.
This directory is the preferred location for additional software
packages that were not part of the initial Linux installation. The /usr/local/bin and /usr/local/sbin directories parallel those higher up in the hierarchy.
/usr/sbinThe bulk of the privileged commands, usable only by the root user.
/usr/srcSource code files for various programs on the system, possibly including the kernel itself.
/varVariable (changing) administrative files, such as log files.






Linux Filesystem Basics


File Names

While technically any character other than slash (/) or the ASCII NUL can be used in a filename (depending on the filesystem),
it's best to restrict yourself to alphanumerical characters (remember that Linux is case-sensitive),
underscore (_), hyphen (-), and period (.).
While
space characters are allowed, they're more trouble than they're worth
because you'll have to enclose the filename in quotes every time you
reference it.


There is no concept of a "file extension" in Linux as there is
in Windows.
It's common to append ".txt" to text files, or ".c" to C source files,
but doing so has no intrinsic meaning to the operating system.
Executable files are identified by their access permissions rather than
an ".exe" extension (see the File Listings section below).

File Types
Almost every "thing" in Linux can be considered some type of file.
The types of files are listed below (note that in this case "file type" does not distinguish a text file from a GIF image file,
but indicates the various "things" that Linux treats like files).
The Listing Character is the leftmost character in the detailed file listing that is displayed using the ls -l command.
The Listing Colour is the colour of the filename displayed by the ls command (in the default Red Hat installation at any rate).
Listing CharacterListing ColourFile TypeDescription
-normal text colour, or green for executable filesregular fileA normal text, data, or program file.
ddark bluedirectoryA directory, containing possibly other files or directories.
llight bluesymbolic linkA symbolic (soft) link to another file. See the Links section below.
byellowblock-oriented deviceA device that reads and writes data in blocks, such as a hard disk. Typically only found in the /dev directory.
cyellowcharacter-oriented deviceA device that reads and writes data in characters, such as a terminal or a serial port. Typically only found in the /dev directory.
pbrownpipe
An interprocess communication (IPC) mechanism.
Also used in memory when piping (|) the output of one program into the input of another using the shell.
Typically only found in the /dev directory.
spinksocket
An interprocess communication (IPC) mechanism.
Not exactly equivalent to TCP/IP sockets.
Typically only found in the /dev directory.


Links

It is possible to create a link to an existing file that, for all intents and purposes, appears to be the original file,
although it may have a different name or be in a different location.
Links are created using the ln command.
There are two types of link: hard and soft (symbolic).


Hard links cannot easily be identified as such, although the
file listing will reflect the number of times a file has been
hard-linked
(see the File Listings section below).
Hard links also have other limitations: directories cannot be
hard-linked (except by the root user), and links cannot cross
filesystem boundaries.


Soft, or symbolic, links are generally preferred because, even
though they act just like hard links, they can easily be identified for
what they are,
and they don't suffer from the same limitations as hard links.

Deleting a link (hard or soft) does not delete the file that is linked to.

File Listings

When displaying files using the long output format (ls -l), a typical file might look as follows:
   -rwxr-xr--    2 sally    managers    48712 Jan  4 09:11 calcpayroll

The first character is the file type, in this case "-" means a regular file.

The next 9 characters indicate the file permissions.
The permissions are split into three groups of three characters each: owner, group, and others.
An r means the file can be read (or a directory can be listed).
A w means the file can be written to, or modified.
An x means the file can be executed (or a directory can be navigated to); in other words it is a program of some sort.
In this case, the first three characters, rwx means that the owner of the file can read, write, and execute this file.
The second set of three characters, r-x means that members of the group can read and execute the file, but not write to it.
The final set of three characters, r-- means that any other user can read the file, but cannot write to it nor execute it.

The number 2 indicates the number of hard links to this file. If there are no hard links, a 1 will be displayed.

sally is the owner of the file.

sally belongs to the managers group,
and members of that group have the access permissions described above (the second set of three permission characters).

The file is 48712 bytes in size.

The file was last modified on January 4th (of this year) at 9:11AM. Older dates will display a year instead of the time.

The file is named calcpayroll.

Filename Expansion

Just as in MS-DOS, the Linux shell can use wildcards to specify filename patterns. This is also sometimes called "globbing".
Don't confuse Filename Expansion with Regular Expressions, which are far more powerful and use a more complex syntax.


Another important but subtle difference is that MS-DOS passes
the wildcard string to the command program for it to handle.
The Linux shell first evaluates the wildcard, expands it into a list of
all of the matching files, and passes this full list to the command
program.
This distinction becomes apparent when you write shell scripts that
accept filename parameters.

WildcardDescriptionExamples
?Matches exactly one character.T?m matches Tim, Tom, T7m, etc.
*Matches zero, one, or many characters.
*.* matches any filename that includes a period (note difference from MS-DOS!),

* matches all filenames,

??* matches all filenames with at least two characters
[set]Matches any one character in set. A hyphen can be used to indicate sequences.
s[aeI]t matches sat, set, and sIt;

*[0-9] matches all filenames that end in a digit;

[a-zA-Z]?* matches all filenames that begin with a letter, and are at least two characters in length
[!set]Matches any one character not in set. A hyphen can be used to indicate sequences.T[!i]m matches Tom, Tum, T_m, and so forth, but not Tim

Filesystems
A filesystem is a device (real
or virtual) that can be formatted to store information organized as
files.
Many different filesystems can, and are, mounted (loaded) into the
Linux directory hierarchy.
Some filesystems have limitations (e.g. MS-DOS's 8.3 filenames, and no
concept of access permissions) but the filesystem driver will attempt
to present
each filesystem in such a way that the user usually doesn't know or
care which filesystem he or she is using.

The following table lists the most common filesystems.
The Type column contains the name used when mounting a filesystem using the mount command.

FilesystemTypeDescription
Second Extendedext2The most common Linux filesystem (prior to ext3).
Third Extendedext3
The latest Linux standard filesystem as of the 2.2.19 kernel but not
included in many distributions until very recently (Red Hat 7.2). ext3
features "journalling" which can help prevent file corruption during
catastrophic system failure (e.g. power failure).
Network File SystemNFSUsed for remote access to files on other *NIX systems on the network.
DOS-FATmsdosUsed mainly for floppy disks. Filenames are limited to the old 8.3 convention.
VFATvfat
The filesystem used by Windows 9x that supports long filenames.
Not to be confused with FAT32 though.
It's common to use this filesystem on multi-boot machines to share files between Windows and Linux.
/procprocThe virtual filesystem used by the /proc directory to display process information.
ISO 9660iso9660The filesystem used by CD-ROMs. Current drivers include the Joliet extensions that allow long or Unicode filenames.
SMBsmbfsUsed for remote access to files on Windows machines (Samba).






Week 2 Linux Commands



The following table demonstrates only some of the options possible for each command.
Consult the man pages for the complete list, or a reference such as

Linux in a Nutshell
.

Help CommandsDescriptionOptionsExamples
aproposDisplay all of the man pages that match the search stringnoneapropos filesystem displays all of the man pages relating to filesystems
infoThe GNU hypertext reader. Displays online documentation for most GNU Project commands. Type q to exit.see documentationinfo egrep displays the documentation for the egrep utility
man
Display the online reference manuals. Type q to exit.
The manual pages are divided into sections: 1. executable programs or shell commands, 2. kernel system functions,
3. library functions, 4. special files (devices), 5. file formats and conventions, 6. games, 7. macros and miscellaneous,
8. system administration commands, 9. kernel routines.
Usually you will be interesting in sections 1 and 8.
see documentationman man displays the online manual for the man(1) command
Navigation CommandsDescriptionOptionsExamples
cdChange directory.none
cd changes to the user's home directory;

cd ~ changes to the user's home directory;

cd .. changes to the parent directory (unlike MS-DOS, space must be between cd and ..);

cd - changes to the previous directory

find
Searches for a file or files that match the specified conditions.
File expansion wildcard patterns must be enclosed in quotes (').

-name pattern find filenames that match pattern;

-type find files of a specific Linux file type

find / -name httpd.conf displays any copy of the file httpd.conf, beginning the search at the root directory;

find /etc -name 'rc*d' -type d displays any directories that begin with "rc" and end with "d" under the /etc directory
ls
List files. If no parameters are given, list all of the files in the current directory.
It's common to have an alias for ls -l called ll,
and an alias for ls -d .[a-zA-Z]*, which displays just the hidden files in a directory,
called l. ("el dot").

-l long format;

-d do not descend into subdirectories;

-a display all files, including hidden ones;

-F append file type flags to the listing (/=directory, *=executables, @=symbolic links, |=FIFOs or pipes, "="=sockets);

-R recursively list subdirectories;

-s display the size of the files in blocks

ls -laFsR ~ recursively lists all of the contents the user's home directory and all of its subdirectories,
displaying block sizes for each file and appending a file type flag to the filename if warranted;

ls -d /etc/rc* displays all of the files beginning with "rc" in the /etc directory without descending into any directories
that begin with "rc"
pwdPrint the full pathname of the current directory.nonepwd displays, for example: /usr/local/bin
File Display CommandsDescriptionOptionsExamples
cat
Display a file or files on the standard output (terminal window). Short for "catenate".
Often used with redirection operators to combine files.
see documentation
cat httpd.conf displays the httpd.conf file contents

cat one two three > all copies the contents of one, two, and three, into all
fileDisplays the type of a file according to its contents.-L follow symbolic linksfile index.html displays: index.html: HTML document text
less
Display the contents of a file one screenful at a time. A "more" capable version of more.
Type q to exit.
see documentationless /etc/profile displays the contents of the /etc/profile file one screen at a time
more
Display the contents of a file one screenful at a time. A "less" capable version of less.
Type q to exit.
see documentationmore /etc/passwd displays the contents of the /etc/passwd file one screen at a time
File Manipulation CommandsDescriptionOptionsExamples
cp
Copy files from one location to another.
It's common to create an alias to cp -i called cp to prevent accidents.

-i prompt before overwriting;

-f force the copy, even if the target file exists;

-r recursive
cp /tmp/foo* . copies every file in the /tmp directory that begins with "foo" to the current directory (.)
ln
Create a link for a file. Hard links cannot cross filesystem
boundaries, nor can they be created for directories unless you are the
root user. The name or the location of the link can be different from
the source file.
-s create a symbolic, or soft, linkln -s /var/log/dmesg kernel.msg creates a symbolic link in the current directory called kernel.msg that points to the file /var/log/dmesg
mkdirCreate a directory.see documentationmkdir foo creates the directory foo under the current working directory
mv
Move one or more files from one location to another, or rename a file.
It's common to create an alias to mv -i called mv to prevent accidents.

-i prompt before overwriting;

-f force the move, even if the target file exists;

-r recursive

mv foo.txt /tmp/foo.txt moves the file foo.txt from the current directory to the /tmp directory;

mv -i foo.txt quux.txt renames foo.txt to quux.txt, but asks first if quux.txt already exists
rm
Delete (remove) files.
Deleted files cannot be recovered
It's common to create an alias to rm -i called rm to prevent accidents.

-i prompt before overwriting;

-f force the deletion;

-r recursive

rm -fr / tmp/* completely erases the entire system,
and anything under the tmp subdirectory of the current directory if it exists
(this is why habitually logging on as the root user is a very bad idea);

rm -fr /tmp/* erases just the contents of the /tmp directory (notice subtle difference from the previous example)
rmdir
Removes a directory, only if it contains no files or subdirectories.
Use rm -r (carefully!) to erase populated directories.
see documentationrmdir ~/tempdir removes the empty directory tempdir under the user's home directory
Filesystem CommandsDescriptionOptionsExamples
fdformat
Low-level format a floppy disk. Run on an unmounted floppy before installing the filesystem.
A non-root user must have write permissions on the floppy device.
-n skip verification stepfdformat /dev/fd0 formats the floppy disk
mkfs
Construct a filesystem on a device. mkfs is a front-end for other programs specific to the given filesystem.
Run on an unmounted device.
A non-root user must have write permissions on the floppy device (and may not have mkfs in their default path).
-t type specifies the filesystem type
mkfs -t msdos /dev/fd0 creates an MS-DOS filesystem on the floppy device;

mkfs.msdos /dev/fd0 same as above, using the specific filesystem mkfs program
mount
Mounts a filesystem to a point in the directory hierarchy. The mount point (directory) must exist and should be empty.
The /etc/fstab
file lists which filesystem mounts are known to the system, and which
can be mounted by non-root users. If non-root users are permitted to
mount certain devices (floppies and CD-ROMs typically) they do not have
any choice over the mount point or the filesystem used. Otherwise, only
the root user is permitted to execute this command.

-t type specifies the filesystem type to mount;

-r mounts the filesystem read-only (required for CD-ROM drives)

mount displays the current mounts (root & non-root);

mount -t msdos /dev/fd0 /mnt/floppy mounts an MS-DOS-formatted floppy in the first floppy disk drive at the location /mnt/floppy (root only);

mount -t iso9660 -r /dev/cdrom /mnt/cdrom mounts a CD-ROM in the CD-ROM drive at the location /mnt/cdrom (root only),

mount /mnt/floppy mounts the floppy using the filesystem specified in the /etc/fstab file (root & non-root);

mount /dev/cdrom mounts the CD-ROM at the location specified in the /etc/fstab file (root & non-root)
umount
Unmounts a filesystem from the directory hierarchy previously mounted using the mount command.
Always unmount a removable-media device (e.g. floppy, CD-ROM) before ejecting the media.
This precaution is necessary because Linux buffers its writes to
devices and your most recent changes may not have been committed to the
media. Even with CD-ROMs, it's a good idea to unmount the disk so that
Linux doesn't become confused. Under certain circumstances a non-root
user may unmount some filesystems (floppies and CD-ROMs typically) but
otherwise only the root user can execute this command.
see documentation
umount /mnt/floppy unmount the floppy disk;

umount /dev/fd0 unmount the floppy disk (same as above);

umount /mnt/cdrom unmount the CD-ROM
Session CommandsDescriptionOptionsExamples
exitExits the current (sub)shell. Equivalent to logout if run from the parent shell.see documentationexit exits the current shell
logoutLogs the user out of the system. Use exit if you are currently within a subshell.nonelogout logs the user out of the system






Week 2 Class Exercises



Perform all of these exercises through the shell terminal window.


  1. Change your user password on the nfs2 server:

    Use the telnet program to remotely log in to the nfs2 server: telnet nfs2

    Your user name is the first letter of your first name followed by your complete last name.
    Your password is your student number without any leading zeros.

    Change your password: passwd

    You will have to enter your old password first, and then your new password twice.

    Exit the telnet program: exit

    Try telnet-ing back into the nfs2 server using your new password to make sure it works.





  2. Experiment with the apropos, man, and info commands:

    Use the commands whenever you're unsure about the syntax of a command.
    For instance, look up any man pages that mention links.
    Then look at the man page and the info page for the ln command.





  3. Find an example of each of the Linux filetypes on your system:

    Use the cd command to move around, and the ls -l command to view the full listing of a directory.
    Try to find examples of: normal files, directories, links, block devices, character devices, pipes, and sockets.
    Hint: the last four can be found in the /dev directory.
    Use the -d and -F options for ls, together with wildcards, to help identify some of these file types.





  4. Look for files on the system using the find command:

    Search for the following: the ls command, directories under /etc that begin with "rc", the Pine configuration file: pine.conf.





  5. Use the cat, more, and less commands to view files:

    Take a look at the following: /etc/fstab, /etc/passwd, and the pine.conf file from the previous step.
    The first two are relatively short, while the last is probably many screens long.





  6. Create a symbolic link:

    Create a symbolic link in your home directory to the file /etc/passwd.
    Experiment with viewing the file through the link.
    View the listing of the link using the ls -l command.
    Try to modify it.





  7. Create and delete new files and directories:

    In your home directory, create a new directory called "scratch".
    In that directory create a new file using vi called "erase.me".
    You can type whatever you'd like into the file.
    Exit vi and use cat, or less, or more, to view the contents of the erase.me file.
    Try to delete the scratch directory using the rmdir command.
    Delete the erase.me file first and then try deleting the directory again.





  8. View the filesystems currently mounted on your system:

    Run the mount command without any options to view the current mounts. Are there any that you can't explain?
    If you have a floppy disk handy, put it into the machine and see if the mount then shows different information.
    If not, try mount /dev/fd0 first. Don't forget to umount.





  9. Add a HTML home page to your account on the nfs2 server:

    Telnet into the nfs2 server as in the first step.
    Change to the public_html directory.
    Using vi, create a new file called "index.html".
    Enter the following into the file: This is your_name_here's home page..
    Save the file and try viewing it through your systems browser by going to http://nfs2/~your_username/.
    If you want to view it outside of the College, use the URL http://netlab2.yukoncollege.yk.ca/~your_username/.
    You can use this site for the duration of the course for whatever legitimate and non-offensive purposes you'd like.
    The sites are monitored by College administrators for inappropriate content.





  10. Logout and shut down the system:

    Exit the terminal shell program using the exit command.
    Log out of the system through the graphical interface (click the bottom-left icon then choose logout from the menu).
    Shut down the system by selecting the shutdown option from one of the login dialog box's menus.



Week 1 - Introduction to Linux

Week 1

Course Overview, Introduction to Linux, Shell Basics
  • History of UNIX and Linux
  • The Open Source movement
  • The Linux kernel and the GNU utilities
  • Linux distributions
  • Basic shell commands
  • Finding help

Introduction to Linux

History of UNIX and Linux

  • 1965: Bell Labs (AT&T), MIT, and GE develop Multiplexed Information and Computing Service (MULTICS).
    Features multi-user, multi-processor, hierarchical file system. MULTICS never really succeeded as a product.
  • 1969:
    AT&T drops out of MULTICS project. Ken Thompson and Dennis Ritchie
    decide to port Space Travel game to unused PDP-7 minicomputer, and in
    doing so realize it could host a MULTICS-like operating system.
    Thompson and Ritchie (along with Doug McIlroy and JF Ossanna) write the
    Uniplexed Information and Computing Service (UNICS). UNICS is quickly
    renamed UNIX.
  • 1971: UNIX now running on a Digital Equipment Corporation
    PDP-11 with 16KB of RAM (8KB for applications) and a whopping 512KB of
    disk.
  • 1972: Dennis Ritchie and Brian Kernighan modify the BCPL language into B and then C.
    By late 1972, UNIX is largely rewritten in C, allowing it to be ported to other computer architectures much more readily.
  • 1974: AT&T licences UNIX to universities who can clearly see the educational potential.
  • 1977: 500 UNIX installations worldwide.
  • 1980: Berkeley's enhancements released as Berkeley Software Distribution (BSD) 4.1.
  • 1983: BSD 4.2 released, AT&T releases System V, and Sun (also a Berkeley spinoff) releases SunOS.
  • 1984: 100,000 UNIX installations worldwide.
  • 1988: AT&T and Sun join forces to produce System V Release 4, later rebranded as UnixWare and Solaris 2.
  • 1991:
    Linus Torvalds of Helsinki, Finland, decides the free but limited Minix
    operating system is too confining and creates the Linux kernel version
    0.01 for the 386. First version of Linux is so limited, it requires
    Minix to compile the kernel.
  • October 5, 1991: Linus releases the first official Linux kernel, version 0.02.
    The bash shell and gcc compiler could run on this kernel, but not much else.
    Fortunately, a number of interested hackers from across the Internet took up the challenge to build on Linus's work.
  • March 1994: Linux version 1.0 released.
  • 1996:
    3 Million UNIX systems shipped world-wide. Many different brands of
    UNIX: Linux, HP-UX (Hewlett Packard), AIX (IBM), Solaris (Sun),
    FreeBSD, etc.
  • January 2002: There are a guestimated 18 Million users of Linux.

Open Source

GNU and the GPL

  • 1983: Richard M Stallman (RMS) at MIT founds the Free Software Foundation (www.fsf.org).
  • RMS believes all software should be freely available, including source code, without restrictions.
  • Money to be made from service and customization rather than software sales.
  • To
    prove the point, RMS and others start the GNU (GNU's Not Unix) Project
    to duplicate all of the UNIX system utilities and programs and release
    them under a new license.
  • The GNU General Public License (GPL) requires source code
    to be distributed alongside binaries, and that all programs that arise
    from modifications to the source, or that are built on top of this
    source, are also licensed under the GPL.
  • GPL-licensed software can be sold for profit.
  • "copyleft" describes this form of licensing: credit for work, rather than control of the work.
  • copyleft is not public domain: author(s) of the work are still clearly defined.
  • Many
    other Open Source licenses: GNU Library/Lesser General Public License
    (LGPL) does not require products build on top of LGPL-licensed code to
    be released under the LGPL or GPL, Apache, Mozilla, Python, IBM Public
    License, BSD, Intel Open Source License, etc.
  • Linux originally released under restrictions that it cannot be sold, but later released under GPL.

How can Open Source Exist?

  • Volunteers write code for many reasons: necessity (like Linus), to make a name for oneself, and because it's fun.
  • To make money, consider analogy of giving away VCRs but then selling the tapes.
  • IBM
    is a big Linux booster, in part because they make their big money
    through service contracts to support and maintain systems like Linux.

Why Open Source?

  • For popular projects like Linux, so many eyeballs go over the code that very few bugs or security holes last for long.
  • Less popular projects may be very buggy.
  • Easy to create new or custom software based on existing source.
  • Usually free, or at least cheap.
  • Good for the soul. How much more money does Bill Gates need anyway?

What is Linux?

The Kernel

  • "Linux" is just the operating system kernel.
  • The kernel is the intermediary between application programs and the computer hardware.
    The kernel manages: process scheduling, device I/O, virtual memory, file management (at a lower level than the filesystem)
  • The
    kernel protects users and processes from eachother. If a program
    crashes, it should not affect any of the user's other programs, nor any
    of the other users.
  • Linux kernel very stable. Crashes are rare.
  • Windows NT/2K kernel hard to see, except when it crashes: Blue Screen of Death. Usually a device driver is the culprit.

The Operating System

  • Technically, the operating system should be called "GNU/Linux" because only the kernel can really be called Linux.
  • All of the rest of the OS, shell, utilities, networking, etc. is part of the GNU Project.
  • Nevertheless, "Linux" is widely used to describe the whole of the OS.

Why Linux?

  • It's Open Source: free as in speech, free as in beer.
  • Also enjoys the stability and security of a popular Open Source project.
  • 35 years of UNIX knowledge has been built up and almost all of it applies to Linux.
  • Minimal hardware requirements compared with similar Windows or Macintosh systems.
  • Highly configurable. A hacker's delight!
  • Runs on a host of different processors: x86, Alpha, SPARC, PowerPC, ARM, 680x0, and many more.
  • Very popular. Jump on the bandwagon!

Why Not Linux?

  • Not as mature as the other UNIXes, especially on big iron hardware (although IBM is changing this).
  • Not as well supported as the large UNIX products.
  • Still not user-friendly for the desktop. Linux mostly runs on the server.

Linux Distributions

Kernel Versioning

  • 2 kernel versions at all times: stable and development.
  • Stable version is the one to use.
  • Development (or Beta) version is strictly for kernel-hackers.
  • Version numbering is: major.minor.patchlevel
  • If minor number is even, then it is a stable version.
  • If minor number is odd, then it is a development version.
  • Linux kernels obey these rules, but most other software versioning doesn't.
  • As of today, current stable kernel version is 2.4.17, and current development version is 2.5.1.

Distributions

  • You could download the kernel and all of the GNU Project
    utilities, create an install, configure everything manually, and you'd
    have a working Linux machine.
  • Or, you could save yourself a year or so of effort and buy or download a Linux Distribution.
  • Linux
    distributions contain: the kernel, GNU Project utilities, system admin
    tools, documentation, installation tools, hardware device drivers,
    technical support, GUIs (X and window managers), productivity apps
    (word processors, spreadsheets, graphics stuff), and so forth.
  • Companies bundle up all of these files and programs into a Distribution which they then sell, or give away.
  • Version
    number of distributions has nothing to do with version number of
    kernel, or with version numbers of the other distributions for that
    matter.
  • Popular distributions include: Red Hat, Debian, Mandrake, SuSE, Slackware, and others (see Resources section)
  • Red Hat: most popular distribution.
  • Debian: created by GNU folk. Not for the Linux beginner. Tends not to include utilities until they are thoroughly tested.
  • Mandrake: appeals to the first time Linux user. Very smooth installation process.
  • SuSE: favoured by developers.
  • Slackware: one of the first, but takes a very DIY approach to installation and configuration.
  • Most distributions also have different packaging: basic, workstation, server, enterprise, etc.

Distribution Versions

  • Red Hat 6.0 (Hedwig) = 2.2.5 kernel
  • Red Hat 6.1 (Cartman) = 2.2.12 kernel
  • Red Hat 7.0 (Guinness) = 2.2.16 kernel
  • Red Hat 7.1 (Seawolf) = 2.4.2 kernel
  • Red Hat 7.2 (Enigma) = 2.4.7 kernel, with most recent patches = 2.4.9-13 kernel
  • Debian 2.2r4 (Potato) = 2.2.19 kernel
  • Mandrake 8.1 = 2.4.8 kernel
  • SuSE 7.3 = 2.4.10 kernel
  • Slackware 8.0 = 2.4.5 kernel

Shell Basics

What is the Shell?

  • The shell is the interface between the user and the
    operating system. The command prompt and the GUI are built on top of
    the shell.
  • In class, "shell" and "command prompt" will be used interchangably.
  • There
    are a number of different shells available: Bourne (the first), C (uses
    a C-like syntax), Korn (combines best of Bourne and C), the Bourne
    Again Shell (bash, also a combo of the others), and more.
  • The Bourne Again Shell, bash, is the default for Linux and the one we'll use. It is part of the GNU Project.
  • bash
    is responsible for: command line editing, job control, stream
    manipulation (piping & redirection), wildcard expansion, aliases,
    file completion, command history, variables, control structures, sub
    shells, etc.

Linux vs. Windows

  • In Linux, letter case matters: FOO.txt is different from Foo.txt is different from foo.txt.
  • Linux (and the Internet) uses forward slashes (/) when specifying a directory path, Windows uses backslashes (\).
  • Linux commands usually use hyphen (-) for command switches, Windows uses a combination of hyphens and slashes (/).

Logging In

  • There are two types of Linux users: root, and everybody else
  • The root user has complete control over the system, for that reason do not log in as root unless you need to perform a system administration task.
    All other times, log in as a regular user ("student") so that a mistake can't wipe out the system.
  • Linux will display a login prompt. Enter your user name and hit return, and then enter your password and hit return.
  • If
    you log in to a GUI console, you can start the command prompt by
    selecting the shell icon on the bottom of the GNOME (foot in front of a
    monitor) or KDE (seashell in front of a monitor) screen.
  • If you log in to a text console, you're already in the command prompt.

Virtual Consoles

  • You may run multiple independent login sessions through Linux's virtual console feature. Typically 6 of these are available.
  • To access the different consoles, press Alt and one of the function keys F1 through F6 together.
  • Depending on the configuration you may not need to log in when you switch to a new console.
  • The
    virtual consoles are completely independent, you cannot share items
    (like the clipboard, for example) between them. They can share files
    though.

Logging Out

  • If you're in a GUI window command prompt, use "exit" to
    close the window. Then select Logout from the GNOME or KDE main menu
    (bottom left of screen).
  • If you're logged in through text mode, use "logout" to log out of the system.
  • "exit" can also be used to logout of a text mode session.

Raod Map

Class WeekCourse Material and Weekly Learning Objectives
Week 1
Course Overview, Introduction to Linux, Shell Basics
  • History of UNIX and Linux
  • The Open Source movement
  • The Linux kernel and the GNU utilities
  • Linux distributions
  • Basic shell commands
  • Finding help

Week 2
The Filesystem
  • The root hierarchy
  • Navigation
  • Permissions
  • More shell commands
  • Text editors

Week 3


System Startup and the Kernel
  • LILO and GRUB
  • System initialization
  • Runlevels
  • Kernel responsibilities
  • Kernel modules (LKM) and compiling options

Week 4


Networking
  • Network configuration
  • Commands and diagnostics
  • Network File System
  • Samba

Week 5


Security
  • Account security
  • Ipchains and Iptables firewalls
  • Common exploits and defenses

Week 6


Installation Preparation
  • Hardware requirements
  • Networking requirements
  • Disk partitioning
  • Upgrade strategies

Week 7
Installation
  • Installing Linux

Week 8


Shell Programming
  • Control Structures
  • Variables
  • Task automation

Week 9


The Role of the Administrator
  • Responsibilities
  • Ethics
  • Backups
  • Contingency planning

Week 10


Administration Tasks
  • User management
  • Permissions
  • Resource management
  • Processes

Week 11


Administrative Maintenance
  • Log monitoring
  • Log rotation
  • Managing upgrades and patches

Week 12


Services
  • Daemons
  • The Apache web server
  • Database and application services

Week 13


The X Window System
  • GUIs, X servers, and window managers
  • XFree86, KDE, GNOME
  • Installing and customizing X

Week 14


Printing
  • Queues and drivers
  • Configuring printing
  • Managing printing
  • Term Review





About Course

Course Description
This course is designed to provide students with an introduction to the UNIX operating system using the Linux distribution. You will learn how to create; delete, copy, move, and search for information on a Unix system as well as organize information using the UNIX system file structure. Students will be introduced to the screen-oriented VI editor as well as have a chance to experiment with other editors. You will learn how to use the shell and create shell scripts, be introduced to the X Window system and its graphical user interface. We will also spend time exploring UNIX capabilities in the network environment and on the Internet. Students will also look at system administration, job control and some of the utilities that are available.

Learning Outcomes:
By the end of the course the student should have the basic technical knowledge and skills needed to work in a UNIX operating system. As a result of using Linux for training on UNIX, the student will also be able to select, install and maintain a Linux operating system.


Required Textbook:
Guide to Linux Installation and Administration, Nicolas Wells, Course Technology, ISBN 0-619-00097-x

Recommended, but not Required
Running Linux, 3rd Edition, Matt Welsh et al, O'Reilly & Associates Inc, ISBN 1-56592-469-X
Linux in a Nutshell, 2nd Edition, Ellen Siever, O'Reilly & Associates Inc, ISBN 1-56592-585-8
UNIX Systems Administration Handbook, Evi Nemeth et al, Prentice Hall, ISBN 0-13020-601-6