1825 Monetary Lane Suite #104 Carrollton, TX
Do a presentation at NTLUG.
What is the Linux Installation Project?
Real companies using Linux!
Not just for business anymore.
Providing ready to run platforms on Linux
|
Tables of Contents
Introduction to UNIX
Introduction to UNIX
Lesson 1
Processes and Files
The Endless Now Christopher Jay Cox
What is UNIX?
- Network Operating System (NOS)
- Multi-tasking
- Multi-user (out of the box)
- Very flexible
- Difficult to learn/use
- Immensely stable
The Long and Winding Road
- Two major flavors (the 1970's)
- BSD (Berkley Software/Standard Distribution)
- System V (AT&T/Bell Labs)
- WAR! (late 1980's and early 1990's)
- Sun teams with AT&T
- HP, DEC and IBM form OSF
- Two future contenders (2000 and beyond)
- BSD (FreeBSD, OpenBSD, NetBSD)
- Linux (Red Hat, Novell, Mandriva, Ubuntu, ...)
Unix Architecture
- Designed to be portable
- Layered design
Introducing Yourself
- UNIX is MULTI-USER!
- User IDs are numeric representations of users defined on the system (e.g. 4005).
- Group IDs are numeric representations of groups defined on the system (e.g. 4005).
- User Names and Group Names are easy to remember mnemonic mappings to User IDs and Group IDs respectively (e.g. fred is user id 4005 and users is group id 4005).
User Authentication
- Traditional Authentication
- Other Authentication Mechanisms
- Kerberos
- SSH Key
- .rhosts trust files
- LDAP
- Windows Active Directory
Group Authentication
- Every User is associated with a primary default Group.
- When changing current group assignment (if it is possible), some systems may force you to authenticate user a Group password (some UNIX variants do not support this).
Logging In (login)
- Log into an interactive Shell using your User Name and Password.
- You initial login directory under UNIX is called your HOME Directory. Type
pwd (Print Working Directory) to see its name.
Welcome to UNIX!
Login: fred
Password: ********
Last login: Wed Aug 26 12:30:05 from console
$ pwd
/home/fred
Who's On
- Type
id to verify you own an identity.
- Also can use:
whoami , who am i
- Type
who to see who is on the system.
- If available,
w -l gives more information than who .
$ id
uid=4005(fred) gid=4005(users)
$ who
root tty1 12:00:05
fred tty2 14:17:25
$ whoami
fred
$ w -l
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root tty1 - 12:00pm 5:02 0.09s 0.04s -ksh
fred tty2 - 14:17pm 1:03 0.04s 0.02s -ksh
Help Me
man pages - for commands, functions, formats.
apropos - search for a man page.
info hypertext documentation.
pinfo - Lynx-like info replacement.
- Vendor/package specific
/usr/share/doc (Linux)
- WWW search (HTML, PDF, etc.)
- Linux Documentation (sometimes old)
UNIX Fundamentals
- The keys to UNIX are (layman definitions):
- Processes: Programs which execute with some isolation from one another.
- Filesystems: A storage area on disk.
Process
- Owned by a User.
- Can receive messages called Signals.
- Termination results in a Return Code.
- Long running ones are called Daemons or Demons.
- Can start other processes called Child Processes or Sub-Processes and thus become a Parent Process.
- The Ancestral Parent of all is the Init Process.
Process Status
ps - Process Status (System V) (e.g. ps -elf )
-e Show all (every) process
-f Show all (full) information
-l Show more (long) information
-u <user> Show user's processes
ps - Process Status (BSD) (e.g. ps aux )
a Show all processes on terminals (tty).
u Show user oriented format.
x Show processes without a controlling terminal.
Process Status (cont)
- PID - Process ID, a unique number given to a process on a system.
- PPID - Parent Process ID.
$ ps
PID TTY TIME CMD
1012 tty1 00:00:00 -ksh
1022 tty1 00:00:00 ps
$ ps -elf
F S UID PID PPID C PRI NI ADDR SZ WCHAN STIME TTY ...
004 S root 1 0 0 69 0 - 109 do_sel 15:58 ? ...
002 S root 2 1 0 69 0 - 0 contex 15:58 ? ...
...
The Shell Process
- Common Shells:
- Bourne Shell (sh) - Always present (sometimes bash).
- C Shell (csh) - C-like, good for interaction, not for scripting.
- Korn Shell (ksh) - Excellent interactive and scripting shell with broad availability.
- Bash Shell (bash) - Excellent interactive and scripting shell popular on Linux systems.
- An easy way to interact with UNIX. Usually the initial process for a login.
Sending Signals to Processes
- Send a signal with kill -<sig#> <PID>
- List all available signals with
kill -l .
- You can only signal processes for which you have permissions (own).
- SIGKILL (9) is a SURE kill. Cannot be caught (trapped) or ignored (last resort).
- SIGHUP (1) used to be to respond to communication line hang-ups, but now is used to trigger configuration file changes.
Sending Signals (cont)
- SIGINT (2) is used to interrupt a process.
- SIGSTOP (19) can suspend a running process
Signaling Processes from the Shell
- Control-C (
^C ) will interrupt (end) the current foreground process, sending a SIGINT to it.
- Control-Z (
^Z ) will suspend the current foreground process, sending a SIGSTOP to it.
- The command
stty -a can be used to see the key sequences associated with the terminal line characteristics intr and susp which send signals to the current shell process when the key sequence is sent from the keyboard.
Process Job Control
- Job control is available in most UNIX shells.
- Job numbers are given to processes:
- running as a background process.
- suspended (stopped) after receiving a SIGSTOP (typing
^Z ).
- Refer to jobs by job number (e.g.
kill %1 ).
- A job can be changed between background and foreground modes (e.g.
fg %1 , bg %1 ).
- The command
jobs lists jobs under shell control.
Applying Job Control
$ man ps
...full screen display of man page occurs...
^Z
[1]+ Stopped man ps
$ man stty
...full screen display of man page occurs...
^Z
[2]+ Stopeed man stty
$ jobs
[1]- Stopped man ps
[2]+ Stopped man stty
$ fg %1
...full screen display of first stopped man page...
...<type q>...
$ fg %2
...<full screen display>...
^Z
[1]+ Stopped man stty
$ kill %1
[4]+ Stopped man stty
$
[4]+ Terminated man stty
Process Return Codes
- When a process exits it returns a code.
- 0 = SUCCESS
- EVERTHING ELSE = FAILURE
- Return code from the last command is stored in a variable called “?”.
- In most shells you can display the contents of this variable typing
echo $? .
Examining Return Codes
$ pwd
/home/fred
$ echo $?
0
$ pwdirectory
ksh: pwdirectory: command not found
$ echo $?
127
$ kill %5
ksh: kill: %5: no such job
$ echo $?
1
$ kill 1
ksh: kill: 1: Operation not permitted
$ echo $?
1
Filesystems
- A way of dealing abstractly with storage.
- Generally uses the concepts of hierarchical directories containing files.
- Does not have to be local hardware.
- Many different types (partial list):
minix | msdos | adfs | iso9660 | reiserfs |
ext2 | vfat | affs | umsdos | xfs |
sysv | ntfs | coda | ncpfs | jfs |
ufs | hpfs | nfs | proc | ext3 |
udf | smb | cramfs | | |
Disks and Filesystems
- Disks are separated into Partitions.
- Partitions contain Filesystems.
- Filesystems contains Directories and Files.
- Filesystems must be Mounted to be used.
- The Root (or /) Filesystem is mandatory and holds special directories called Mount Points where all other filesystems are mounted.
- The root filesystem is implicitly mounted at / (slash) during UNIX boot up.
Disks and Filesystems
Logical Volume Management
- Instead of partitioning, a Logical Volume is an allocation from an available set of storage extents, possibly even across devices.
- Can migrate data easily.
- Easy growing of filesystems (e.g. reiserfs) allow you to grow (increase size) while mounted.
- Avoids the ''running out of slices" problem.
- Sun and others often call a partition a slice instead.
- LVM is supported on most UNIX and UNIX-like platforms.
UNIX Devices
- Filesystems are accessed through special files called Device Files located in
/dev in UNIX.
- You mount the filesystem device onto a mount point directory.
- Filesystem devices are Block oriented devices (move data in chunks) and are usually cached.
- Other hardware also uses special Device Files located in
/dev for access.
- Terminals use Character oriented devices (move data byte-by-byte).
Filesystem Structure
- Logically: Contains files and directories.
- Physically: Just files.
- Each file is identified by an Inode number (a number guaranteed to be unique within a filesystem). It contains the information about a file including where to get the file's contents.
- Special files called directories contain a table of names-to-inodes.
- Filesystem hierarchies are traversed by moving from directory inode to directory inode.
- The
. file entry in a directory is a self reference to that directory inode.
- The
.. file entry in a directory is a reference the parent directory inode.
Filesystem Structure (cont)
Filesystem Operations
df - Disk Free, shows the mounted filesystems and the available space on each.
du - Disk Usage, shows space that a directory or files is using.
mount - (root user) Associates a device (filesystem partition) with a mount point directory.
umount - (root user) Disassociates a device with its mount point.
dd - Device-to-device copy.
df
df -k
df -H
- Disk space in readable form (Linux and Solaris 9 or higher).
du
du [<dir>|<file>]...
- Total space from this directory downward of all files and directories.
du -s [<dir>|<files>]...
- Total space for directory.
mount
mount <mount-point>
- Mounts device associated with mount-point in /etc/fstab.
mount [-t <type>] <device-file> <mount-point>
- Mounts device-file onto mount-point.
mount -o <options>,... ...
- e.g. read only,
mount -o ro ...
umount
umount <mount-point>
- Disassociates the device with the mount-point. For this to succeed, no one can be using the filesystem.
dd
dd if= <device-file> of= <device-file> ...
- Can be used to clone disks with the same physical attributes (cylinders, heads, ...)..
- Tons of options for handling block size differences.
- Often used to read foreign tapes, including EBCDIC mainframe tapes.
- Device-file could be a filesystem file.
Directory and File Operations
ls - List directory.
pwd - Print Working Directory
cd - Change Directory.
mkdir - Create Directory.
touch - Create an empty file, or adjust current time stamp of existing file.
cp - Copy files.
rm - Remove files and directories.
rmdir - Remove an empty directory.
Directory and File Operations (cont)
mv - Move inode directory entry to a different name or different directory.
cat - Concatenate files. Can also be used to see the contents of a file.
ls
ls -l
- long listing, shows permissions, links, size, etc.
ls -a
- show hidden files (files that begin with a “.”)
ls -i
ls -F
- show classification characters.
ls -t
- sort by modification time.
cd
- By itself, return you to your HOME directory.
cd ..
cd .
cd /
- go to the root directory.
Pathnames
- Specifying a pathname that does not begin with a
/ means that the path is relative.
- Paths that start with
/ can contain relative elements though.
/etc/../usr/../etc/passwd
cp
cp <file1> <file2>
- Copies <file1> to <file2>
cp <file1> <file2> <filen>... <dir>
- Copies <file1>, <file2>, etc. to <dir>
cp -r <dir1> <dir2>
- Copies all of <dir1> into <dir2>
cp -p ...
- Copy preserving permissions and times (if possible)
rm
rm <file1> <file2> <filen>...
rm -i <file1> <file2> <filen>...
rm -f <file1> <file2> <filen>...
- force inspite of permissions
rm -r <dir1> <dir2> <dirn>...
- remove recursively all of directory.
Links
- Hard link is the same file inode present in different directories.
- Soft link is a pointer to an inode, the soft link has its own inode.
ln <file1> <newhard1>
ln -s [<file1>|<dir1>] <newsoft1>
- You cannot create your own hard linked directories!
Summary
- UNIX has a HUGE history.
- UNIX can be viewed as processes and files.
- UNIX is truly multi-user.
- Hardware devices are accessed via device files.
- The parent of all filesystems and directories is called the root.
- The parent of all processes is called init.
END DAY ONE
|