UNIX Notes: - Del Mar College



UNIX(/Linux Notes: Professor: Michael P. Harris

v.20050412

UNIX( is a multi-user, multi-tasking operating system originally developed at AT&T Bell Laboratories. It provides programs for editing text, sending electronic mail, preparing tables, performing calculations and many other specialized functions that require separate application programs in other operating systems. One of the key identifying features of UNIX is its standardized directory and file structure.

Typical UNIX/Linux root /

Directory structure: (

((((((((((((((((((((((((((((((((((((((((((((((((((((((((

bin etc dev mnt lib lost+found home tmp sys boot unix

( ( (

default ((mounted ((((((((((((((((((((((((((((((

(((((((((volumes) mike teri ... etc bin lib spool

hd0 fd0 sd0 (users home directories)

There are many different versions of UNIX. One of the most important is the line of UNIX releases that started at AT&T, the latest being System V Release 4. Other important UNIX versions have come from the University of California at Berkeley; the latest is called BSD4.4. Microsofts Xenix, a early popular microcomputer implementation of UNIX was originally based on an earlier AT&T release called System V. Linus is currently the leading popular “Open Source” implementation of a Unix-like standard operating system. POSIX is the validation standard, set for UNIX-like operating systems. Starting with Windows 2000 Pro, Windows 2000, XP, and 2003 are all now POSIX compliant. Other major versions of UNIX include SunOS, Solaris, SCO UNIX, AIX, HP/UX, ULTRIX, NOVELL UNIX (Univel), and the various implementations of the popular Linux OS.

Since it started more than 35 years ago, UNIX has grown and changed in a different way from most operating systems. Many early UNIX users were computer and scientific professionals; more than a few of them extended UNIX by adding tools and functionality to do what they needed. UNIX was also used to develop a lot of the powerful networking systems that connect the world, such as Internet. So, whereas most operating systems were typically developed and controlled by one corporation, UNIX has been developed through a collective effort. This has meant more versions and somewhat more confusion than "standardized" operating systems like MSDOS & Windows. But it has also helped to make UNIX the flexible and incredibly rich and powerful operating system that it is today.

UNIX and its derivatives were not designed as "user-friendly" operating systems, in fact, UNIX has, in the past, earned its label of "user-hostile." UNIX can be used the way it was originally designed, on typewriter-like terminals (ttys). Most modern versions of UNIX can also work with window system GUIs (Graphical User Interface) which allow each user to have more than one "terminal" on a single display. The X Window System (called X for short) is the most common UNIX window system. The appearance of X Windows may vary between systems due to different window managers. Four of the most common window managers are mwm (Motif Window Manager), olwm (Open Look Window Manager), CDE (Common Desktop Environment) and the new Linux windows shells Gnome, KDE, fluxbox, and others.

Getting Started:

UNIX can be overwhelming with its barrage of details. To get started though, all you need to do is master just a few details:

o How to Log in and out of your system

o Understand the Shell and how to control the system with control characters

o Learn the important UNIX specific directories and files

o Manage UNIX files and directories, including listing, creating, copying, printing and removing files, and moving in and out of directories

o Work efficiently using UNIX pipes, filters, and multi-tasking.

Logging In:

Before you can start using UNIX and its facilities, the System Administrator has to set up a UNIX account for you with your login name, password, and home directory. At many sites, there will be a whole network of UNIX computers so you may also have to know the hostname of the computer that has your account as well. When you turn on your terminal you should see a message from the UNIX computer that looks something like:

login:

Logging in is the process of making your self know to the UNIX computer and getting into your account. On remote systems you will need to run a remote login program like telnet, rlogin, cu, or tip. In this case your login session might look similar to the following: (what you type is in bold-italic)

telnet nutshell.

Sun Solaris OS

mercury.delmar.edu: Solaris UNIX version 9.00.10

login: mpharris

Password: ********

Last login: Wed Mar 29 14:34 CST 2005, from mercury.delmar.edu

motd: The "crisis" of Today is the "joke" of Tomorrow

REMEMBER !!!

We will be shutting down at 4:30pm for system backups.

Fri Apr 1 12:24:48 CST 2005

$_

The UNIX Shell:

Once you've logged into a UNIX computer, you're working with a program called the shell. The shell interprets the commands you enter, runs the program you've ask for, and generally coordinates what happens between you and the UNIX operating system. There are three shells in common use: the Bourne shell, Korn shell, and C shell. For the novice the differences are slight however some to run some software or execute some program (especially shell scripts) you will need to know which shell you are using (ask your system administrator). The only immediate difference you will see is that the Bourne, Korn, and Bash shells prompt you with $_ while the C shell most often uses %_ as the prompt. Certain keyboard commands (keystrokes) are interpreted by the shell, these are commonly called control characters. The basic control characters are:

Ctrl-C or [DEL] Interrupt character (interrupts or cancel a command)

Ctrl-D Returns you to UNIX command level. Used to signal end of input. ** Also logs you off of most UNIX systems

Ctrl-H or [BACKSPACE] Erase character to left of cursor

Ctrl-Q Restart output after paused by Ctrl-S

Ctrl-S Pauses output to the screen

Ctrl-U Erase the whole input line so you can start over

UNIX( vs. MSDOS(

The UNIX operating system has been around much longer than MSDOS. While MSDOS owes much of its original heritage to a single-user operating system named CP/M, MSDOSevolved gaining more and more UNIX like capability. MSDOS is not case sensitive meaning that commands can be typed in either upper or lower case and MSDOS treats them all as if they were typed in UPPER CASE. UNIX is case sensitive meaning that there is a difference between a command typed in upper or lower case. The UNIX standard is that commands are typed in lower case. A brief comparison of MSDOS and UNIX command equivalents follows:

CD pwd

CD DIRNAME cd dirname

CHKDSK fsck

COPY FILE1 FILE2 cp file1 file2

COPY FILE1 + FILE2 FILE3 cat file1 file2 >file3

COPY FILENAME PRN pr filename | lpr

DIR ls

DIR /W ls -C

DIR /P ls | more

DEL FILENAME rm filename

MD DIRNAME mkdir dirname

REN FILE1 FILE2 mv file1 file2

RD DIRNAME rmdir dirname

TYPE FILENAME cat filename

File Access and Permissions

An important point to always remember is that in UNIX everything is a file. The textbook definition of UNIX usually goes something like this...

UNIX - a multi-user/multi-tasking interactive operating system developed by AT&T. UNIX has a directory structure that is tree-like with files containing all the information that is part of the system.

Most people familiar with microcomputers and MSDOS are familiar with the tree-like directory structure with directories, sub-directories and pathnames. But in UNIX the directory structure and file system are the heart of the system. UNIX is also device independent there for no duplication of commands is necessary for different devices such as the screen, printer, or disk drives.

For example, UNIX always keeps the files in its directory structure is a sorted order, there for to rename a file is really moving that file within the directory structure. To copy that file to another directory, to the screen, or to a floppy disk drive is the same command because UNIX is device independent, everything is a file, the destination directory, the screen, the auxiliary storage device are all files to UNIX. This concept may take a little getting used to before all that is means sets in.

To log into a UNIX system your terminal must be described to the system. In the directory /dev the system device files (files that contain the hardware interfacing information UNIX needs) are contained. In addition, your terminal type is stored in /etc/ttytype, your terminal speed in /etc/ttys, and your terminal setup and capabilities data in /etc/termcap. The advantage of this system is obvious, if you change your terminal or enhance its capabilities, your just edit the system files. In addition you can have multiple definitions and settings for multiple different users.

The UNIX executable commands are kept in a the /bin directory with miscellaneous system data files kept in the /etc directory. Unix commands are usually short and terse and most always in lower case. UNIX filenames may include A-Z, a-x, 0-9, . and _. After UNIX boots from the kernel code stored in /unix directory, the /etc/rc startup file is executed. This (reboot cold) startup file would be the equivalent of the MSDOSCONFIG.SYS and AUTOEXEC.BAT files. The system default setup information is stored in the /etc/default file.

When users log into a UNIX system, there access is controlled by password and access information stored in the /etc/passwd and /etc/group files. Once logged in users are met by the users login message-of-the-day stored in the /etc/motd file and then the users personal startup and setup commands are executed from their own private .profile file stored in their /home/username login/home directory.

One logged into the UNIX system file access is controlled by the standard UNIX permissions: r w x -. The permission settings are for Read, Write (or change), eXecute, and permission denied (-). The permissions are grouped into a set of three rwxrwxrwx where the first three are the permissions for the user/owner of the file, the second three are the permissions for members of the group assigned to the file and the last three permissions are for all others who may wish access to the file. The command chown is used to change the owner of the file. The command chgrp will change the group assigned to the file. And the command chmod (for change access mode) will change the file permissions. Of course, you must have write permission to change the owner, group assignment, or permissions to a file.

As an example, assume the ls command (list single file) gave you the following permission settings for the file /etc/motd... rwxr-x--x

These permission settings would indicate that the owner (usually supervisor) has Read, Write, and eXecute permissions to the file. Those who have the assigned group access permissions can Read and eXecute the file, all others may only eXecute the file.

When changing permissons to your files with the chmod command, you have the options of a, u, g, and o (for All, User/owner, Group, and Others) the syntax is:

chmod options filename

where options can include:

(1) a, u, g, o (2) + or - and (3) r, w, x in any combination.

For example: chmod g+rx myfile

would add Read and eXecute to the group portion of the permission settings.

Alternate Input / Output, Piping, and Redirection

The Unix commands for redirecting Input and Output are:

> redirect output < redirect input

>> redirect output append wholist

would execute the who command (generate a list of who is currently logged on to the system) and pipe the output into the input of the sort command (alphabetize) and the sorted list would be written to the file wholist.

and... banner < wholist >>register

the file contents of wholist would be fed into the command banner (which generates large bannerized letters from file contents) and add this output to the end of the file register.

UNIX DIRECTORY GUIDE

Typical UNIX/Linux root /

Directory structure: (

((((((((((((((((((((((((((((((((((((((((((((((((((((((((

bin etc dev mnt lib lost+found home tmp sys boot unix

( ( (

default ((mounted ((((((((((((((((((((((((((((((

(((((((((volumes) mike teri ... etc bin lib spool

hd0 fd0 sd0 (users home directories)

/ UNIX root directory

/bin UNIX Commands (binary files)

/boot UNIX file system bootstrap loader programs

/etc miscellaneous system data files

/etc/default system default setup files

/dev peripheral device control files

/lib libraries for the 'C' compiler

/lost+found depository for misplaced files

/mnt empty directory to mount file systems

/sys code for UNIX kernel (operating system)

/tmp temporary files (may be auto deleted)

/home users master/personal directory (or /usr, or /user)

/ home /bin more commands usually user created

/ home /lib more language libraries and data files

/ home /spool print spooler master directory

/ home /tmp users temporary files

/ home /asm administration accounting files

/unix executable code for UNIX kernel

UNIX FILE GUIDE

. name of current directory

.. name of current directory's parent

.profile set up environment at login (personal startup file)

/etc/group designate group 'names'

/etc/logbook logbook of installed software

/etc/motd (message of the day) login message for users

/etc/passwd define system users and access

/etc/rc define system initialization and startup commands

/etc/systemid define system name

/etc/termcap define standard terminal setup information and capabilities

/etc/ttys define terminal port status/speed

/etc/ttytype define default terminal type

/ home /lib/crontab time & date for auto execution

/ home /adm/messages record of console messages

Sample UNIX / home directory with subdirectories:

/

(

home

(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((

adam betty edward mark ...

( (((((((((( ((((((((((( ((((((((((((((((((

(demo1 memo etc letter util fax pgms news bin fax make

(demo2 ( ( ( ( (

(mm1 (let1 (fax1 (jan (mod1.c

(mm2 (let2 (fax2 (feb (mod2.c

(let3 (mar

all users have a .profile file in / home /username/.profile

ALPHABETICAL LIST OF UNIX COMMANDS

The commands in the Basic System are listed below in alphabetical order.

asktime set system date and time

assign assign a device to a user

at execute commands at a later time

atq examine the "at" job queue

atrm remove a job from the "at" job queue

awk pattern scanning and processing language

banner print large letters

bc arbitrary-precision arithmetic language

bdiff compare very large files

bfs scan big files

cal print calendar

cat concatenate and print files

cd change working directory

chgrp change group

chmod change mode (change access permissions)

chown change file owner

chroot change the process root directory

cmp compare two files (any type)

comm select or reject lines common to two sorted files

copy copy groups of files

cp copy

cpio copy file archives in and out

cron execute commands at specified times

crypt encode or decode a file

csplit split files according to context

cu call the UNIX system

date print and set the date

dc desk calculator

devnm identify device name

df report the number of free disk blocks

diff compare two text files

diff3 compare three text files

dircmp compare directories

dirname deliver the directory part of a path name

disable turn terminal use off

dtype print disk type (such as Xenix, msdos, tar)

du summarize disk use

echo echo arguments

ed invoke text editor (line editor)

egrep search a file for a pattern

enable turn terminal use on

env set or print the environment for command execution

ex text editor (line editor)

expr evaluate arguments as an expression

false provide truth value by returning with a nonzero exit code

fgrep search a file for a pattern

file determine file type

find find files

finger find information about users

fsck check file system for consistency and repair if necessary

grep search a file for a pattern

grpcheck check group file

haltsys shut system down

hd give hex dump of a file

head give first few lines of a file

id print user and group ID and name

join join two relations

kill terminate a process

l list directory contents in long form (equivalent to ls -1)

lc list directory contents in columns

learn give computer-aided instruction about UNIX

line read one line

ln make a link to a file

login give access to the system

logname get login name

look find files in a sorted list

lpr send files to the line printer queue for printing

ls list the contents of a directory

mail send, receive, or dispose of mail

mesg permit or deny messages sent to a terminal

mkdir make a directory

mkfs make a file system

mknod make a special file

mkuser add a new user account

more display a file one screen at a time

mount attach a file system to a directory on the root subtree

mv move or rename files and directories

newgrp log into a new group

nice run a command at a different priority

pack compress files

passwd change login password

pr print a file

ps report process status

pstat print system facts

pwcheck check the password file

pwd print the name of the working directory

quot summarize file system ownership

random generate a random number

remote execute commands on another machine

restor invoke incremental file system restorer

rm remove a file

rmail send mail among users

rmdir remove a directory

rmuser remove a user

rsh invoke a restricted a shell

sdiff compare two files side by side

sed invoke stream editor

setmnt establish a mount table (/etc/mnttab)

settime change file access and modification dates

sh invoke the Bourne shell

shutdown shut down the system

sleep suspend execution for an interval

sort sort or merge files

split split a file into pieces

stty set terminal options

su make the user root or another user temporarily

sum calculate checksum and count blocks in a file

sysadmin perform file system backup and restore

tail deliver last part of a file

tar archive files

tee create a tee in a pipe to save intermediate output

test test conditions

touch update file access and modification times

tr translate characters

true return with a zero exit value

tset set terminal type

tty get terminal name

unmask set default file creation mask

unmount detach a file system from the root directory

uname print the current UNIX name

uniq report repeated lines in a file

uucp copy files from UNIX to UNIX

uulog copy files from UNIX to UNIX

uux execute commands on remote UNIX

vi invoke a screen-display editor based on ex

vsh invoke the visual shell

wait wait for background jobs to finish

wall write to all users

wc count lines, words, and characters

what identify files

who list users currently logged on

whodo show who is doing what

write send a message to a user's terminal

xargs construct argument lists and execute commands

yes print string repeatedly

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download