Tải bản đầy đủ (.pdf) (6 trang)

Quick study computer LINUX 600dpi

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (14.88 MB, 6 trang )

Li nux has its roots in UN IX. A brie f history
UNIX is, therefo re, cruc ia l in understanding it.

UNIX
Came from Bell Labs in the late 1960s and I 970s.
It was des igned to a ll ow the staff to share infor ma­
tion, store and manipu late data , and do research.
They all owed various universiti es to obtain the source
code fo r free , for research into operating systems.
As the un ivcrsiti es worked on the operating system.
vari ous ve rs io ns dcvelo ped that \Veren't compatibl e
with each other, but the comm crcial viability as an
operati ng systcm was beginni ng to be realized .
Bell Labs stopped sharin g the source code and the
versio ns of UN IX began to be more ti ghtly con­
trolled by the orga ni zati o ns that had control over the
vanous versIons.

Enter Minix
Minix was based on the Bell Labs vari ant and was
the f irst real vers ion of U IX to be avail able on the
IBM PC plat form.
It was created by Andrew Tanen baum, a professor in
I iolland. He managed to fit th e OS into an 8086
class Pc, and then made the so urcc code avai lable
for his classes and others.
Li nus Torvalds bega n with M inix and started tin ker­
ing with it at the University of He lsin ki. He decided to
create his own vcrsio n o f UN IX that woul d be free ly
avai lable, have more capabili ties than M inix. and have
no licens ing restrictions for those who wanted to con­


tribute to th e project , other than keepi ng the product in
the public domain. O ne of the first versions (0.02 ) of
what was to become Linux was an no un ced on the

comp .os.minix ncwsgroup on October 5th, 199 1. By April
1992 , the new OS had enough of a foll owing to get its own
newsgrollp, comp .os.linux. TCP/ Ip support was added in
August 1992 and things continued to be rapidly updated
and upgraded towards the goal of a 1.0 re lease (before
th is , Lin ux was at O.xx releases ), whi ch occurred on
March 14th. 1994. Starting in March of 1995 , two ver­
sions of Linux were available, 1.2.x and 1.3.x. The num­
bering standard is as follows: major or Kerne l vers ion
(cu rrently 2), m inor version or kerne l patc h level (for
example, 2 ), and a sublevel (for example, 14). Th e kernel
patch level is the most interesti ng feature of the number­
ing scheme : Even numbers are stable vers ions of the ker­
nel. Odd numbers are versions that are sti ll in deve lop­
ment and are cons idered experi menta l. Hoth arc freely
avail able. with prod u<:ti on syste ms and the major distrib u­
tions all using the stable versi on, and developers and those
on the " hleeding edge" favoring the odd-num bered ver­
sions. O n June 9th . 1996, kernel version 2.0 beca me avail­
abl e, and it (the 2.x kernel) is still what is in use and what
w ill proba bly be in use fo r the next few years to come.
Each provider o f Linux ca n get th e source code, tools,
utili ties , graphical envi ronments, and so on t,'om the
Internet and then wi ll typi cally hundl e them together with
other appl ication programs, games, programm ing tools,
and so on as he/she deems most useful. Each of these var­

ious bund les are ca lled Di strib ution s, and are produced by
many compan ies, including Red Ilat. Ca ldera, SuS E.
Debi an, and Slackwarc. to name a few. Today, Linux also
runs on many hardware platforms, incl udi ng Intel (and
clones), Motoro la 68000 series , PowerPC , Compaq Al pha.
and MI PS , to name a few. T his compa res favo rabl y w ith
many other operating system s that only fu nction on a sin­
gle platform.

Creating. modifying. and deleting users and gro ups
can be done with various programs in a graphical
environment (such as with COAS [Caldera Open
Administration System]. included with Caldera's dis­
tributions or available at www.coas.nr).!) or at a
command prompt. While graphical sys t e n~s arc more
user-friendly and often automate many things that must
otherwise be done manually, they al so vary \\ idely. so
wc will focus on the T U I meth ods here.
The three primary commands for manipulating users
are useradd, usermod, and userdel, but they are not
needed if you choose to edit the primary fiks directly.
All user in fo rmation is stored in /etc/ passwcl except fo r
the user's encrypted passwo rd, whi<:h is stored in
lete/shadow. G roup inti)1'mati on i~ ston:d in /<:Ic group
(except It)r the user's primary grou p, whi<:h is storcd in
letc/passwd). The syntax of all three utilities is as fol­
lows: <command> foption( s )] < user na111e >.
Common options for useradd incllu.k:
• -g <group name or number> - user's pri­
mary group

• -G groups the user he longs to. separated by commas
and without any spaces
• -m - creat e h0111e directory ifit docsn't already e ~i st
• -u <UID> - user ID (UID) num bL'r; de fault is the
next ava ilable UID (I t I lighest UID)
For usermod, the sa111e opti o ns li sted I,)r useradd
are ava ilable (exccpt - Ill). Note that if the UID is
changed, ownership o r all file s out s ide o f th at user's
home directory will not be updated. ( For more inlo r­
mation on rile ownership, sec th e secti on on penni s­
sion s and ownership below.) T here is also a -I Slvitch to
change the user's log in namC'.

LOGGING IN &: OUT
Logging In
To be ablc to access resources on most comput ­
ers, you must fi rst identify yourself to the operating
system by supplying a use r I D and pa ssword. Linux is
no except ion. Li nux, like UNIX , is case-sen sitive in
most aspects of it s o peration, and that is true of User
IDs and pa sswo rds as well . System admini strators cre­
ate them (as described in Us er & Croup M(lIliplI/atioll)
and supply thcm to users as needed. Logging in can be
accompli shed either in text mode or in a graphical
mode, depending on the di stributi o n, your preferences,
and th e way the system is configured. In any case, oncc
a va lid name and password are entered, you will be lell
at either a "$" prompt (for most normal user accounts)
or the "#" prompt (for the root. or super uscr) if you

logged in in text mode (a TUI, or Textual User
Interface) or to a GUI (G raphi cal User Interface) desk­
top environment if you logged in from a graphical
prompt. Note that the prompt can vary, but "$" and "#"
arc th e most common.

Changing Passwords
O nce a user has logged in, his or her password may
need to be changed. This may be forced at intervals'
de fin ed by a system admini strator, or done by the tree
choice of the user. The root user can always change
anyonc 's password; other users may only change the ir
own . Whe n choosing pa sswords, be sure to stay away
froi1l words (especially names of famil members,

pet s, and so on that arc easily guessed) and s imple pat­
tern s. Try and use a combination of upper and lowe r case
letters, numbers, and special symbol s (such as " @" or
" 'Yo" ) to make the password harder to guess , bllt avoid
mak ing it so hard to guess that the password can't be
remembered. and therefore, gets wri tten down .
To change passwords, simply lise the passwd command
at any command prompt. You will be prompted for your
old password (unless you are root. in whi ch ca se, you mu st
specify the user you want to change passwords for as an
argument to the passwd command, as in passwd and then 1()r your new password, which you will have to
type twice to make sure you enter it correctly. Assuming
that you entered both the old and new pas sword s correct­
ly, you will get a message that the password was success­

fully changed.

Logging Out
To logout of a GUI system, choose Logout from the
main menu (it varies from GUI to GUI), or if you are in a
TUI, either type logout or exit. Be sure to always logout
when you have finished working to make sure that some­
one else can't use your system to do things as you. Note
thai in some GlJ I environment s, there is also a Lock
Workstation option, which will lock the workstation so
that no one can use it until your name and password are
specified, but you remain logged in and any process ing
going on can continue.

The userdel command ha s only one o ptiona l switch.
-r, which will remove th e user's home directory and all
files within it. Be very careful whcn using thi s s\\ itch
to make sure that there arc no important fil es in the
home directory or 1llove them elsewhere first.
For those wishin g til add users by directl y cditing
the files directly, simply use vi or your I:woritc editor
to edit /ete/passwd. Th e l,mnat or that file is as "'"o\\ s
(the
<:ol<)JJs
arc
field
(klimiters ):
"U ser
Name:Pa ssword: Uscr ID (number):Clrnup I D (nU111­
bcr): Comment:Homc directory:DeEllIlt shell." As tur

the uscr I D field, while people usc the use r name field.
Linux use s this number internally to refer to the user.
such as I()r file ownership and permi ssi ons. It is simi­
lar to the SID (Security ID) in Windows NT. The pass­
word fi eld will contain a lower case letter .x, meaning
that the actual password i ~ encrypted in Ict clshado\\.
Group ID is the user's primary g roup (recall that the
rest arc in lete/group). The comment fi eld normally
contains the user's full name. The home directory will
usually be " /home/ < lIs"r 1Ia/1/" > ." except for roOI.
which normally has a home directory of '·/root." The
default shell in Linux is "/bin/bash." although others
are available.
Group management is primarily a manual pro<:ess
involving editing the letc/group file. The format of the
file is as follows (the colons are fidd de limiters ):
"Group name:Group password:Ciroup ID (number):
User l/all/l!S of group members." Th e group pa ssword is
very rarely used. Thc user name field takes any num­
ber of user nam cs , separated by commas: ic I CI /III.1'l1'llete/group. fete/"h adOlI:

LlNUX SHELLS &: COMMAND LINE
A shell is the intcrt~\c e that users and administrators
use to access the operating system. The shell provides
access to commands, filc s, and other system
resources . Shcll scripts, mini-programs similar to
DOS batch file s, can also be created and can range
from simple to extremely complex. Shells in Linux
fa ll into two categories, the Bourne shell and the C

shell. The Bourne shell family is older, but more wide­
ly used, and a successor to the Bourne shell, the
Bourne Again She ll (usually called bash), is thc default
shell in Linux. It has great script support. The C shell
was written for those who arc comfortable program­
ming in C. The shells themselves are located in the !bin

directory. Note that some commands and virtually all
scripts written for one shell won 't work with another shell.
To determin e your current shell, simply type:

$ echo $SHELL
/bin/bash

$
Shells other than Ibin/bash may be displayed.
General syntax of any command in any shell follows
this general format:
command (options( (parameters(
Command is the command you want to execute
(remember, it is case-sensitive), options (sometimes called

switches) modify the behavior o f the command and arc
typically preceded with a hyphen. and paramete rs
(sometimes also called argument s) arc th e data or fil es
the command needs to act on or with. For example. in the
command "Is -I *,conf." Is is the command or program
to run, -I is an option that show s mor details ahout the
files (modifying how the command beha\'es ). and *,conf
refers to the type of files desired, namely those ending in

".conf."
Multiple commands can be entered nn the same line,
if desired, by separating each command with a semi­
colon (";"); for exampl e, "who; uptime."


!/3t

t;, ","':11:

I;Jy

THE LlNUX FILE SYSTEM
The reason you logi n lO lin uh is to do work of some
sort, such as v\fiti ng a letter, setting up DNS, or surf­
ing the Internet. In all ca,es, you will be worki ng with
files. Fil es and directories in li nux arc case-sensitivc,
sO lS, Is, and ls arc all di fTc rent files. There arc thou­
sands of files installed with the operat ing syste m, and
users and administrators may create th ousands more.
To bring organi.tation to all of this in form ation, direc­
tories ca n be creatcd . The figure below rcpresents a
typica l linux file systcm, with important directories
for the configurat ion of the system or the funct ioning
of the system in bo ld.
The

Lill/IX

File system s(Yllctllre


I


I

I

I

rcl.d

sysc6nfig

jni~.d

I

net workM
script s
bin

sbin

doc

1

v~r P~O( rolot


,J

g sp601

m~iI

oht

sbin

d aerhons

src

Note that th e root of the entire fi le system is " I,"
called root. All fi les and directories exist under root.
There may even be mult iple hard dri ves and parti tions
under th is single root. Un li ke some other operat ing
systems, there is ever only one root. Directori cs, sub­
di rectories, and files are separated with the " I" charac­
ter, as in "/etc/rc.d!i nit.d/network," where etc, rc.d, and
init.d and all directories and network is a fi le. A brief
summary of importan t directories foll ows:
• letc - many conf iguration files are stored here (and
in subdirectories of letc ), inc lud ing those for the
GUI, DHCP, the supported filesystems, and PPP.

• letc/rc.d - used when the system starts and by the in it
command to start or stop sys lem daemons; the actual
scripts are in letc. rC.d init.d and ·etc. r.d rC<II>.d, where

11 is the ru n level being started or changed to.
• letc/rc.d/in it.d - scripts to start and stop individual
daemons, such as PCMCIA services, network services,
and printi ng.
• letc/sysconf ig · system configuration f il es and sub­
di rectories Ihat contain various configuration files.
• letc/sysconf ig/network-scripts - sc ripts to con­
trol network adapters; named like i/cI.~-eth () for the f irst
Ethernet adapter, ifcfg- Io for the loopback adapter, and
so on.
• Iva r/log - logs of system activity; some daemons
store their logs in su bdirectories of this one, suc h as for
Web services (usua lly Apache).
• Ivarlspool - prin ter spool fi les awai ting printing,
faxes awai ting faxing, mail to be sent andor rece ived,
and so on .
• lus r/bin - many programs and shell scripts, such as
clear, ca l, and so on that do not provide the most basic
of functionality.
• lusr/l ib - library fil es or shara ble libra ries (simi lar to
.Dll fil es in Windows) tha t many app lications use.
• Ibi n - system prog rams that users need and have access
to, such as cp bash, and Is; others are in lusr/bi n.
• Is bin - system programs that adm in istrators need
acccss to, such as ifco nfig, fd is k, and ipcha ins.
• Idev - represen t physical devices attached to the sys­
tem for parallel ports, seria l ports, hard drives, flop py
drives, and so on.

Directories

Whcn you first login, you wi ll be left in your home
directory, which is a place where you can keep all of your
stuff. It is typically located somewhere under hOllle. To

find out \vhat your home di rectory is, simply login and
usc the p\\d (print working directory) command as
shown belov\.

$ pwd
/ home/ briannall
$
In this case, the user's home directory is located
di rectly be low /holll(, and is namcd hrial/!lIIh, which
is also usua lly the user's login namc. Whcnever bri­
annah needs to store any filcs, she should do so herc.

Fi les
A file is simp ly a co ll ect ion of data, such as a lettcr,
an emai l, or even a program. In l inux, unlike some other
operating systems, a file may bc nailled anything and the
type of the rile is not necessa rily easily discernible. For
exaillple, in DOS, a rile naillcd " MOVE.EXE" will alilm
yo u to Ill ove a file frolll one dircctory to anothcr, \\hile
in l inux, the comilland mv is used (note, there is no
".e.xe" or anyth ing else in the nallle). Many files have
com mon ex tens ions, such as .con rig or .c, but these are
typicall y by convention only and can be named anything.
You Illay create your own directory structure bclov\ your
hOllle directory to organize data any way that makes sense
to you. such as creating separate directories for each proj­

ect you are work ing on or 1'01' the type of app lication, sueh
as email or letters. When referring to files and directories,
you can usc two approaches, namely:
• Absolute. Use the full location of the file, starting
at root.
EXlIIllple: /holllC/hriolllwh leiters "'(lllege-lIl'pliClltioll

Re la ti ve. Start \V ith the current (or working) L1irec­
tory when referring to the fi le.
­
EXl/mples: 1r:1I('i"Scol/ege-lIJipliclItiol/ (if" hrialliw/l il
ill h<'l" hOIll(, directOl:") or col/ege-lIlll'licrllioll (if"
is lIlre(/(~,' ill lellen)

,I,,·

Us ing Directories
There arc seve ral com mands for usi ng and mani pulat ing directori es:
- go directly to home dircctory
- - return to the last directory you were in (this comman d is bash-specific)
I - go to thc root directory
Idir - go to the directory named dil; directly under root
dir - go to the directory named dir under the current directory
.. - go up one directory
..1•. - go up two directories

WILDCARDS

• cd
• cd

• cd
• cd
• cd
• cd
• cd

Wildcard characters are spec ial characters that arc expantkd by the shell he/il!"!'
the resu lts are passed to the command that is entered. They are most onen used
when listing, copy ing, moving, and deleting riles. Ihe available vvildcards arc:
Wildcard Effe ct
* Matches zero or more characters
') Matches anyone character
[chars] Matches any o f the characters in chars; individual characters
may be listed or ranges may be specified by separating the start­
ing and en ding characters in the range with a dash
[!chars] Matches any of the characters Ilot in chars: indiv idual charac­
ters or ranges may be speci fied

Examp l es: cd //lsrlhill: Go dirl!ct'" to the dirl!ctolT / lI.W"lhil1 (llote thl! ohsoillte pat/I)
cd ..femail -go lip ()Ill! 11'1'1'1. t/I('l1dOIl'1I to tileellla il directory (llote the relatil'e path)

Creation an d del etion of directories arc done wi th thesc comma nds:

• m kd ir d ir - create a direct ory namcd elir under the cu rrent di rectory (absolute paths
may also be used)

• rmd ir dir - remove an emp ty di rectory na rned

dir un der the current direc tory
(absolute paths may also be used)

Example: rill - r /IromeihriwI/UI/! : RemOl'1! hriallllah:, home directol:" all d el'<'I)'filing in it.

The simplest way to understand the use of wildcard characters is by looking at sev­
eral cxamples. All of tile exampics arc based on the files in a directory, as shown here:
$ is
andrew
a shley
bricmna
carin
robert
$ is a'

Viewing the Conte nt s of Dire ctor ies
To see what is in a di rectory, use the Is command . A directory name may also be spec­
ified to see what is in that directory. Thi s com mand takes many optional switc hes that
can drastica lly alter the output. Some of the more co mm on variants of Is arc:
• Is - lists the conten ts of the Cli rrent directory, displaying fi le anci directory names only
• Is -a - same as Is, bllt al so di spbys hiddcn f iles (those that start with a ".")
• Is - R - displays contents of the current directory, including the contents of all direc­
tories and sub directories be low this directory
• 15 - I - di splays a long (detailed) listi ng or the fi les, as Sl!en here:
-rw-r- -r"
1 root
root
16 Nov 1805 :1 7 HOSTNAME
drwxr - xr'x 9 root
root 1024 Nov 18 05 :08 XI I
drwxr-xr-x
3 root
root 1024 Nov 18 05:12 config .d

lrwxrwxrwx
1 root
root
11 Nov 18 05 :06 rmt -> ../sbin/rmt
- rw - r - , r ' 1 root
root 5927 Mar 15 1999 se rvices

andrew
$ Is ' a '
andre-w
$ Is ' a
b rianna
$ Is ??????
andrevf
$ Is [b-c)*
briann a
$ Is [!a -c]*

The output is sp lit into seven colu mn s as foll ows:
I. Access perm issions (described in the Permi ssio ns and Ownership section)
2. Number of links to thi s fi le/di reclOry (si mi lar to shortcuts in Wi ndows 9x)
3. User owner of the fi le/directory
4. Group owner of the fil e/directory
5. ize of the file in bytes
6. Date or tim of last modi ficatio n (month, day, hour, and minute if with in the last si x
mon ths; othc m ise, the month, day, and year)
7. File or di rectory name

a shley
a shley


bricmna

a shley

robert

carm

carin

robert

$

PRINTING

Printing is setup with the Ipd eommantl and can be quite extensive. Many distribu­
tions have automated printer setup and installation mechanisms, such as with COAS.
Once printing has been setup, users can use the Ipr, Ipq, and lprm commands to submit
print jobs, view the items wai ting in the queue for the printer, and to remove print jobs
that are no iongcr needed. The syntax of cach of these three commands is as follows:
I/O REDIRECTION
Com ma nd Description
One of the most powertlll and onen-used feature s of linux is the ability to take the
Submit a fi le named .file (a print job) to the
Ipr I' output of a command and send it to another command or file. The three basic symbol s
printer named printer
used in redirection arc " > . <, and I." They arc typically used (in the bash shell) as follows:

Ipq P [user] View al i of thc jobs awaiting printing by the
Redirection
Result
pri nter nailled prillfer, opl ionaily display­
cUllllllllnd < file
Usc jile (instead of the keyboard) as input to conlll/lIIui
ing only jobs for user user; infollnation dis­
("(IIIIIIWIIiI > .fi!t:
U se /ile (instead of the screen) for the output 01'("0111­
played includes: user namc, posit ion in the
lII(/1ul, but errors are still sent to the scn:en
queue, job ID (number), and sizc (in bytcs)
Same as the last example, but append the output of COIII­
COIIIIIIWIiI » file
Jprm P

<job ID> [user] Remove the print job wi th numberjoh ID from
IIllllld to the end ofjile instead of overwriting the contents
pri nter pril1ler; if logged on as foot, a user
COllllilalid >/ile l 1 > /ile2
Send the output of cOllllllalld tojilc ! and the errors to/ile2
name may also bc specified, othcrwise, on ly
Take the error output of cOlI/llland. redircct and com­
ClJIIIIIWl1Ii 2 >& / > /il1'
your own jobs !llay be removed
bine it with the standard output, and send both to/ile
Many other options can be specified to print various Iypes of files, control page
Take the output of cOlllmand I and use it as input to
cOllllllalli! I / COIIIIl/llnd 2
widths, and so on. Consult the man pages for complete deta ils.
cOfl/llland2


2


~&:4h..' ".:tl.:.u,.

THE VI EDITOR
There arc several edi lors available fo r Li nux, but the
two most popul ar are VI and EMACS. Most Linux users
use VI. VI can be used for any editing purpose, but is
most often used to edit config urati on files, she ll scripts,
and so on. T he commands used in VI are also q uite cryptic. Once you have the m memori zed, you w ill fin d
Ihal you can be very prod ucl ive. In the mea ntime,
this qu ick reference w il l probably be one of your
mosl used pages.
To start the program, simply Iy pe vi 10 open it with a
blank documcnt. Most o nen, however, you will wanl to
open a file when the program is invoked. To do so, type vi
<file> and VI will open with the cursor at the top of the fi le.
T he progra m is a lways in one of two mo des: inpul or
com mand . In input L11 ode, you enler new text, whereas
in comm and mode , you g ive VI commands 10 perfo rm
va rious inst ruct ions, such as save the fil e or ex it the
program . You are always in command mode. unl ess
you enler inpul mod by one of the commands li sted
be low. To get oul o f inp ul mode, press Ihe Escape key.
Most commands take the form of ( II) colI/lI/alld ohiecl.
v\ here cOI11I1 /{/Ild is any of the commands li sted be low,
obiecl is what you want to act on (letter, word li ne. and so
on; may be a movement command ). and II is an optional
number of limes to repeat the comma nd. For example, the

command 3dd would delete the nex t th ree lines.
The command summary below i, divided into sever­
al secti ons to fac il itate finding the commands you need .

Commands to Switch to Input Mode
C o m m and
a
A
I
o

o

Purpose
A ppend text just to the ri ght of curSOl'
Append text at the end of the line
In sert tex t at cu rre nt c ursor posi tion
Insert text on new li ne below current li ne
Insert text on new line just above
current linc

Gener a l Com man d s

Search & Replace Commands

C om ma nd Purpose
:q
Quit vi ( if text is unsu\cd, prom pt the
use r to save first)
;q!

Qu it vi , los in g any unsaved changes
Write (save ) the file, optionally to fil e file
:w(file1
Write (save) the f il e. th en qu it
zz or :wq
Inserl the contents o fJile at the c urrent
:rfile
cursor posi tion
Changin g & De leting Text Commands
C o m ma nd Pu rpose
R
Type-over mode, with in sert mode at
end of line
cw
C hange the next word to the text you
next type; le ft in in sert mode
cc
C hange the entire line with the text you
specify: left in insert mode
dd
Delete the cur rent line
Del ete the line li'om the cursor to the
D
end o f the line
Delete the line from the beginning to
dA
the cursor
dG
Delete from cu rsor to the end of the file
Undo the last change made

u
x
Del ete the charac ter the cursor is o n
Del ete the cha racter to the left o f th e
X
c ursor (like backspace)
Copy & Paste Com mands
Com ma nd P urpose
p
Paste (in sert) text last copied to ri ght of
cursor
Paste (insert) text last cop ied to len ufcursor
P
yy
Yank (c opy) current line
Yank (copy ) from curso r to the end of
ye
the wo rd

C ommand
Ifill" lexl
.
/
)f711" lexl
'I

n
N

:slfilld lexll

replace lexl
:0'05/f7I1d lexll
replace lexllg

Pur'pose
Search fro m cursor fOI'ward for/ill" leXI
Repeat the last forwa I'd search
Search from cursor backward for fill" I<'xl
Repeat the last back ward search
Repeat the last search (forward or
backward )
Repeat last sea rch in opposite direction
Replace the first occurrence of /illd I<'XI
with replllCt' II'XI on the current line
Replace a\l occ urrences ofjilld I<'XI
w ith rcplll(,t' rexl

Movem ent Comm ands
C o m m an d
j or <enter>
k
I o r <space>
h or <backspace>

o
A

G
w


b
(
)
:
:
II
L
<' ctrl> f
<ctrl> b

Pu rpose
Dow n one line
Up one li nc
Ri gh t one character
Left one cha racter
Move to the beg inni ng of the line
Move to th fi rst non-b lank charact r
on the line
Move to th e end of the line
Go 10 the end of the f il e
Forward o ne wo rd
Backwa rds o ne word
~ love backwards one scntence
~ I O\e l'orward on c sen tence
Back o ne paragrap h
Forward one paragra ph
Move the c ursor to th e top of the cur­
ren t sc ree n
Move cursor to the bottom of the screen
Down o ne screen

Up one sc reen

PERMISSIONS & OWNERSHIP
Permissions dictate if users can access a file/d irectory, and if so, what they can do
with II. Permissions arc closely tied to ownershi p. There are thr e main permissions:
• Read. Symbolized by the letter "r" in an Is, it lets users view the contents of a file
or view the file and directory names in a d irectory.

• Writ e. Symbolized by the Icttcr "w," it a ll ows users to cha nge the contents o f an
existing file if applied to a fi le, o r to create, de lete, and rename files if app lied to
a directory.
• Ex ecute. Symbolized by th e lettcr "x," it allows users to run a program or
she ll script ifset on a file, or vie\\ the fi le an d dir ctory names in a directory ifsct
on a directory.

Who is Affected
Letter
u
g
o
a

Action to Take

Symbol

+

Ow ner ship
Fvery fi le and directory has an owner, in fact, two owners, namely, a user and a

group. Permissions can be set fo r a user, for a g roup, and fo r everyone else (often
called th e world), as described below. To view your use r name and a il of the groups
you belong to, use the id comma nd.

Ex planation of Per missions in an Is -I
The first fie ld of the ou tp ut of an Is - I is made of 10 col umns. Th e first colum n is
one of three thi ngs: a "-," mean in g it is a fil e, a "d," meaning it is a d irectory, or an
"I," meaning it is a lin k to another fi le or di rectory. The remaining nine col um ns arc
grouped into subgroups of three letters or sy mbols, one group each for user ( f irst
three), g roup (second three ), ane! everyone else (l ast three ). Each g roup o f three rep­
resents read, write, and cxec ute permissions, in that order. If a spec ific type o f access
has been g ranted to a given gro up, a letter (r, W, o r xl w il l be in th at col umn : if it is

not grantctL a "-" , ill appear in stcad.

When determining a g iven user's access to a file, it w ill first eheck to ,ce if that
user is the user owner of the f ile . I f he/she is, access is g ranted as spec if icd by the
user pe rmi ssions. If not, the systcm checks to sec ifthc uscr bel o ngs to the group that
owns the fi ic. If he/she docs, group permissions arc used. In all other cases. the world
permiss ions are used.

o

Vlca ning

Add li sted permission(s)

Remove listed permiss io n( s)
Set the permissions to the listed permission(s)'
regardl ess of previous val ue


Thc perm issions are the standard read (r ). w rite (w ). and exec ut e (x) .

Ex amples of Setting Permissions
Perm issions arc set \\ ith the chmod utility. Th si mple, t way to understand thi s utility is
with some examples. The o utput of a sample Is - I below wi il be used in a \l of the examples.

- rwx - - - - - -rwx- - - - - - rwx' - - - - -rwx- - - - - -rwx- - - - - -

1
1
1
1
1

Desired Result
File
User
taxes .'.!'.!
budgel.OO
logo
Is
suggestions

Setti ng Permissions with Numbers
As there arc three prima ry permi ssions, and as 2 3 &, it fo ll ows that all o f the pos­
sible comb ination s can be descri bed as a si ngle number from 0 - 7, where the execute
rig ht = I, write - 2, and read = 4. There fore, the rights assigned and the eq uivale nt
nu mbers arc as follows:
Permissions Assigned

Nu m ber
None (- - - )
I
Execute (-- x)
2
Wri te (-w -)
3
Write and execute (- w x)
4
Rcad (r--)

5
Read and execute (r x)

6
Read an d write (r w -)
7
Read. \\ rite, and cxecute (r w x)
Permissi on, arc assigned to the appropri ate use r. g roup, and the wo rld, by using
three numbers in a row, suc h as 700 or 750, where the f irst number is fo r user, th e
second l'or g roup, and the last for everyo ne el se (th e world),

Mea ning
user

group
other (world)
all (user, group, and other)

rw

rw
rw
rx
I'

root
root
root
root
root

root
10
root
5
root 48800
root
12
root
9

Feb
Feb
Feb
Feb
Feb

15 21:00
1521 :00
1521:01

1521:01
15 20:59

chmod with
Gro u p Oth er num b ers
none
non~
600
rx
non
650
644
rx
rx
555
w
w
422

budget.OO
logo
Is
suggestions

taxes.99


chmod with letters
(many p ossible)
u-x

u-x,gtrx
1I rw, g r. o- r

a rx

u- r, g+lV. o tvy


Setting or Changing Ownership
Now that yo u know how to set perm issions . and you knovy thn! permi ss io n, arc set
on users, g roups, and everyone ebe, ho\\ do you cha nge ownershi p (user o r g rou p) ofa
fil e or di rectory" You use chgrp to change group ow nership , or chow n to change u s~r,
and opti ona ll y group, ownership . T hc sy ntax of chgrp i, ch g rp <grollp > <file(s; >,
where g roup is either a group name: or 10. Addi ng the -c sw it ch "ill di sp lay cach fiic
that is changed and the change made. For example:

$ chgrp -c managers budget.OO
r oup of b udget.OO changed to mana gers
T he syn tax o f chown is chown <1I.ver> cha nged, or chown < lIser>:<grollp> at once. A period may be used instead of thc co lon as the sepa rator. Note that either J
namc o r a number may be used fur the user and g ro up owners. For example:


Setting Permissions with Letters & Symbols

$ chown 237:8502 logo

owner of logo chang ed to 237. 8502
$ 15 -llogo

- rwx- - - - - 1 briann ah managers
$


If you fine! the preceding systcm a litt le cryptic, yo u can choose to set, adeL or

remO\'e indiv idua l perm iss ions from users, groups, and eve ryone using letters and
symbols. instead. T here are three things that must be known to set permiss ions: who

is affected what act io n to take . and the permi ssion or permissions invo lved. The let­
ters and symbol s arc as fo ll ows:

3

5

Feb 15 21:00 logo



Linux shells mainta in a fai rl y comprehen sive set o f
environmental \ ariabl es that can be viewed by anyone, as
well as used by admi nistrators and program mers in shell
scripts. The operating system also uses these variables.
User-defi ned variables may also be created and mani pu­
lated. We will only discuss the Bash shell in this section.
Some common and useful shell variables are:
HOME. Path to the user's home d irectory
• PATH. Used by the she ll to f ind programs w hen
the path to the prog ra m is not spec ified; eac h

path is separated by a co lon
• PS1 . Co m ma nd line prom pt (o ften " " )
• PS2. Seco ndary prom pt whe n mo rc inp ut is
needed (often" >.,)
• PWD. The current d irectory
• SHELL. Name of the e ur rcllIly runn ing she ll
(usually'"/bin/bash" )
• $$. Process ID (PID ) of current shell ; lor use with ps

Displaying a Variab le's Contents
To vi ew the value o f any variabl e, simply usc the
echo command followed by the va riable name. The
vari able name must have a do ll ar sign ("'$") prepelld­
ed to the na mc, so for exam ple, you would ty pe
,. HO ME: ' Two cx.t mp les o f using variabics fo llow:

$ echo $PWD

jusr/ b in

$ echo $HOME

/home/briannah


Setting a Variab le

Predef ined shell variables may be changed in value
and new ones created at a command prompt by si mply
typing "<I'tlriahle> = <lIallle>." Most often, user­

defined vari ables wi ll be created (for use in a shell script.
for example) or the PS I, PS2, or PAT H variables will be
modi fi ed. ote that the S is not used with the variable
namc whcn setting it, but is used if referring to a vari­
able 's value on the value side. ome examp les will help:

$ echo $PWD
jete
$ PSl=$PWD
jete DATE="07/04/01"
jete echo $DATE
07/04/01
jete
To make the variable useable in any shell beyo nd
the o ne in whi c h it is set, the export command m ust be
used. The syntax is " expo rt <I'tlriable>," once aga in
without the $ prepended to (he \'ariable name.

FINDING FILES &. DIRECTORIES
Files and d irectori es may be found by two di ffer­
ent methods: the fi nd and the locate commands .

locate
T he locate command is faster a nd causes less of a
stra in on th e syste m beca use it searc hes th ro ugh an
index of all files stor d on th e hard drive in a f ile
ca ll ed localedh . Th is fil e is usually updated da ily by
a cron j ob that runs th e u pdatedb co mmand . Th e
database may be re freshed at a ny time by ru nnin g
updatcdb as well. The downs ide to thi s co mma nd is

that new f i les may not be in the database yet, o r the
updating of the database may con sumc vita l system
resou rces to bring it up to date . For exa mp le, scarch­
ing fo r the location o f localedh is do ne us ing thc fo l­
lowing synta/< :

$ locate locatedb
/ etc / eron .d / Daily/ 50update-locatedb
/ e te / eron.d/lib/update-locatedb
/ usr/ man/ man5/1ocatedb,5.gz
/ var/ state/ locatedb
$
Note that mo re f iles may be returned tha n ex pect­
ell depe nding o n what is be ing searc hed fo r.

f ind
The lind command is more comprehensive. allowing
you to search for files with a given namc (by using the
- name option ), with given permission s (by utilizing the
- perm opti on), of a given si7e (with the -size option),
or a certain type (via (he - type option), to name just a
few options. T he power o f ihi s command lies not only in
its ability to locate fil es. but in its ability to then act on
each fil e found in so me manner (via thc -exec option).
The basic forma t of the command is '"lind
<-optioll(5j>," The func tionalit y o f thc loca te com­
mand (only the sea rc h is done on the current di recto­
ry informatio n instead o f from a file) can be achieved
by using the fo llowing command:


$ find/-name locatedb -print

/ var/state/locatedb

$

In that example, the "/" is the directory from which to
start searching, in thi s casco root. Thc - name option te lls
lind to locate a file named "Iocatedb. " and thc - print
option te lls find to output the location to the screcn,
I f wildcards are used in searching for a fi le, they must
be enclosed in quotation ma rks. For examplc, to get the
same results as the locate example g iven abo. e, ente r thc
cOlllmand ,·tind I -na me '*Ioeatedb *' -print."
If you wanted more than thc location of the file only,
instead of using the "-p rint" option, use "-Is" in stead. In
that case, the output would look Iike that from a Is - I
command . Many other sw itches a rc available; see the
man pages for cOlllplete in fomlation on this eommand.

g rep
Thc grep utility w ill allow yo u to searc h th ro ugh a
file for any text you spec ity. This can be used to find the
occ urrence o f anything in a fiic. fo r example, th num­
ber of times that your company name occ urs in a docu­
ment or the number o f users who LIse thc bash shcll. To
determinc the number o f users using the bash shell. you
must reme mber that the dc fault shell for a user is stored
in the /elc/plJ.\·,\'l\'d file. Thc command to do so is:


$ grep -e '/bin/bash'/ete/passwd

8

$
What if you wanted to know how many dicln't usc
thc bash sheW' Usc this variation:

$ grep -e -v '/bin/bash'/ete/passwd
3
$

The , .~" option tells grep to display a count. instcad
of thc actual lines, and the " -v" option says to look fo r
all lines that don't have the pattern tcxt in thc m.

FTP (File Transfer Protocol) is usc(l as its name
imp lies, for transfening files between two computers.
The beauty of FTP is that the two computers can be
any type and both can run any operating system. For
example, one cou ld be a Linux system and the other,
Windows machine or Macintosh. FTP allows for both
anonymous and authenticated access. Many systems
on the Internet allow anonymous access to download
drivers, patches, and so on, as well as offering authen­
ticated access to download program updates and other
fil es that are only available to paying customers. Many
browsers allow for FTP access as well.
To use FTP from the command prompt, simply
ty pe ··ftp <hostll{lllle>." When logging on anony­

mous ly, log on as user " anonymous," using your
e mail add ress as the password.
Once you have becn authenticated the follow­
ing commands are ava ilable (l isted by type):

Transfer Mode
• asci i - set the tra nsfer mode to text o n ly (non­
text data w ill not transfer eorrectly with this
opt ion set); the defa ult
binary - set the tra ns fcr mode to binary,
allowing all types of fi les to be tra nsferred,
bina ry (program) as we ll as text
Est ablish & Terminate Remote Sessions
• bye - exit ftp a nd return to a shell prompt
• open <hostnam e> - create a connection
with the computer namcd haSlnallle

Directory M anipulation
• cd <dIrectory> - change to directory din'c­
larl' on the re mote computer
led <d i rectory> - change to directory (liree­
on the local compu ter (default is the direc­
tory that ftp was started in)
• Is or di r - display the filcs on the remote sys­
tem in the current directory; filenames or wild­
cards may a lso be specified as described in the
Linux File System section above
• pwd - print the working (currcnt) directory on
the remote machine
• mkdir <directory> - create a directory

na med direclol'l' on the remote machine
IOrt '

Fi le Transfer .
• get <filename> - get the file named jill'­
IWlIle from the remote machine and place it on
the local machine

• mget <filenames> - multiple Get; gets all
ofjilellame specified from the remote machine;
wi Idcards may be used

• put <fi lename> - send jilenulIle to thc
remote mac h ine from thc current directory on
the local maehine
• mput <filenames> - multi pl e Put ; sends
filename to the remote machi ne
• 'delete <filename > - dc le tes the filc namcd
.filename on the rc mote system
• mdelete <filenam es> - mult iple Deletc;
deletes all of the f iles specified on the remote system

Miscellaneous
• prompt - togg les thc prom pt to send receive,
or de lcte m uli iple f il es o n or o ff

• help - Di splays he lp in fo rmation of available
cOlll mands for ftp

! <command> - execute the cOl11mand namcd

comll1and on the local systc m. w ithoui ex iti ng ftp

ARCHVING RLES &. DIRECTORES
Often. you will want to place a bunch o f info rma­
tion in a sing le fil e. like is onen done with various zip­
ping prog rams in DOS/Windows. suc h as PKZIP or
WinZ ip, T his is great \\ hen you need to ema il severa l
fil es to a co llcague or comprcss and storc a bunch of
files you don't often usc, but don 't want to delete. In
such cases, the tar (Tape A Rchive ) utility comes in
very handy. Olicn, you will want to not only store
many fil es in one file, you will a lso want to com press
the file s wiihin that file. Aga in, thc tar utility comcs
to the rescue. A ll fil es you specify, as well as fil cs in
all subdirectories o f the cu rrent (or spccified) direc­
tory. will also be includcd.
There a re a lot of options avail ablc for the tar
command. Important options rail into two catc­
gories: func tion options and gcnc ral optio ns. You
must a lways usc on e (and only one ) fu nctio n option ;
all othe r options arc d iscretionary.

Function Options for tar
• -c - crcate a new arch ive file
• -r - add file s to the e nd of an existing archive
• -u - update the archive with new files. or exist­
ing f ilcs that have been updated
• -t - display the names of the files in the archive
• -x - e xtract f iles from the arehivc


Other Options for tar

• -f - file na me of the archive file

.• -v - ve rbose: dis play the filename s as they a re

• -z

added or removed from th e archive
- usc gzip to compress the files as they arc
added to th e archive or gunzip to unco mpress
them as they are extracted

A simple examplc of using tar follows :

$ tar -em names.tar •
andrew
ashley
brianna
carin
robert
$

To get the fil es back out of the archive, the tar
command is al so used. The data will be extracted in
the curre nt directory. All files in subdirectori es will
be expanded into their original subdircctory names.
To uncompress the previous archive, usc the follow­
ing command: " tar - xzvf na mes.tar."


gzip
The gzip utility can also be uscd to z ip individual
files to a compressed format. The gunzip utility is

uscd to uncomprcss suc h compressed fil es . By
de fault, simply running gzip o n on.: or more riles
wi ll compress th em and a uto mati ca lly acid a '".g/" 1\1
the end o f thc file nam e. Similarly. runni ng gU llzip
on one or more compressed f il es w ill a utomat ica lly
uneo mprcss the m and re move the " .g/ ' from the
end of the fik name.
Finally, what if yo u wa nt to \'iew the content s ,)1
a compressed file" Do YOli need to gunzip it fir, t to
view the contents. only to gzip it aga in" No . You can
use i he zea t or zmore utiliti es to "icv\ a com pressed
text file. Let's ill ustrate the use of gzip. gunzip. a nd
zeat with an c>.ample .

$ gzip message

$ eat message.gz

-: , U 98 mes,;;qge

EE,V ¢D 6:UAc.e .. .U66:aA6T. 56:&­
$ zeat message.gz
T his is a small message,


$ gunzip message.gz


$ eat message

Thi s is a small message .


$


ve
fo
fo
Ip


Each of the shell s in Linux o ffe rs scripts that set
up the envi ron me nt for users of that she ll. They are
sim ilar to autocxec. bat in the DOSfWindows envi ­
ro nment. Each of the files listed are for the BASil
shell and arc located in each user's home d irectory
(except for fetcfp rofiIe) . Othe r conf igurat ion fi les
may also exist.
Script Name Function
.profi le Run s a t login to set the user's
environm ent, includi ng environ­
ment al variables, such as the
path and comma nd prompt
.bashrc Run s eac h time a new bash she ll
is started (which can happen
multi ple times fo r a s ingle

log in)
fetcfprofi le Log in script fo r all users on the
system to set g lobal settings

$ps
PID TTY

$ jobs
[l]+ Running
Is -l-R/home >
HomeDirListtxt &
$ Is
HomeDir LisUxt
[l]+ Done Is -l/ home >HomeDirLisUxt
$
This example will do a long listing of the fhome
directory, recursively through the subdirectories,
piping the output to l-IomeDirLisUxt and do the job
in the background. Note that as soon as the com­
mand is entered and the < Enter> key is pressed, the
system returns the job number "II and the process
ID of that job (in this case, 887). While the job is
running, its status (along with all other running
jobs) can be viewed with the jobs command.
If you forget the ampersand at the end of a com­
mand and find it is taking a long time to complete,
you can take that process and change it from a fore­
ground to a background process by pressing
<Ctrl><z>. That keystroke combination will sus­
pend the process. To take that suspended process

and make it a background process, type bg. Once a
task is executing in the background, it can be made
a foreground task with the fg command. Both fg and
bg allow an opt ional job number to be speci fied as
a parameter.
There are several important notes regarding fore­
ground and background processes, and jobs in gen­
eral, that you should be aware of, namely:
A process that is in the background and needs
user input will be suspended until it is brought to
the foreground and supplied the necessary input.
Output from a background process will display
on the screen as it is gcnerate(l unless output is
redirected to a file .
When you logout, all unfinished background jobs
are terminated by default.

TIME CMD

854 pts/l
894 pts/l
$

00:00:00 bash
00 :00:00 ps

TIME CMD

1 ?
2 ?


0000:04 init
00:00:00 kflushd

?

?
?
?

pts/O
pts/ l
pts/ l

00 :0000
000000
00:00:00
0000:00
000003
00:00:00
000000
00:00:00

kpiod
syslogd
inetd
rpc.portmap
X

bash


bash

ps

or

$ ps-e
PID TTY

?

If you want to terminate a process that is not
responding or that you otherwise do not want to
keep running, usc the kill command. The synta x
the kill command is kill <PID>.
To view the top consumers of memory and C PU
time, use the top command. The inf(Jrlllati oll is
updated frequently, and is similar to Task Manager
in Windows NT or Windows 2000. T he output will
be similar to the following (many lincs have been
removed to save space):

To view all of the processes on a systcm, use the
-e switch. The output of this command is as follows
(note that many of the processes have been eliminat­
ed from the output to save space):

$ top
12:56pm up 1:03, 3 users, load average : 0.53, 0.15. 0.05

48 pr=esses: 46 sleeping, 1 running, I zombie, 0 stopped
CPU states: 0 .6% user, 0.2% system, 0.0% nice. 99 .0% idle
Mem: 127988K av, 94092K used, 33896K free, 46576K shrd,
Swap
OK av,
OK used,
OK free

JOB CONTROL
In Linux , as with UNIX,jobs are normally run in
the foreground. The problem is, if you have a long
task, it can prevent you from doing anything else for
a long time. You have three solutions - switch to a
new virtual console, open a new terminal window in
the GUI , or run tasks in the background. To switch
to a new virtual console, press <Ctrl><AIt><Fn>,
where Fn is a function key from F I - F8 (F7 and F8
are usually for the graphical screens) and login
again. Opening a new terminal window in your GUI
will depend on the GUI , so it will not be discussed
here. The third approach is running a task in the
background and is the focus of this section.
To run it task in the background, simply append
an ampersand, " &:' to the end of the command line,
as illustrated here:
$ Is -1 -Rjhome > HomeDirList.txt Be
[1] 887

3
537

596
598
778
853
854
896
$

A process is simply a program that is running. It
may be a program that you start as a user or a sys­
tem process, such as a daemon. Each process has a
numbcr, called a Process ID (PID). To view active
user processes, issue the following command:

40484K buff
29228K cached

PID USER PRI NI

SIZE

RSS

SHARE

STAT

LIB %CPU %MEI\I TIME COM;\1AND

907

1
2
119
537
540
590
596
598
621

1052
436
0
324
568
800
572
540
396
892

1052
436
0
324
568
800
572
540
396

892

852
372
0
268
460
384
436
440
320
728

R

0
0
0
0
0
0
0
0
0
0

root
root
root
root

root
root
root
root
bin
root

18
0
0
0
0
0
0
0
0
0

0
0
0
0
0
0
0
0
0
0

S


SW
S
S
S
S

S
S
S

2.9
0 .0
0 .0
0 .0
0.0
0 .0
0 .0
0 .0
0 .0
0.0

0 .8
0.3
0.0
0.2
0 .4
0.6
0.4
0 .4

0 .3
0 .6

0 :00
0 :04
0 :00
0 :00
0:00
0:00
0:00
000
0:00
0 :00

top
init
kflushd
update
syslogd
klogd
cardmg r
ine td
rp::.p::lrtmap

amd

The two most important columns (generally) are the % C PU and 'X,M EM , which del"ine th e pe rcentage 0 1"
C PU time and the percentage of total memory used by that process (note that total memory is displ aycd in
the header information). See the man pages for detailed information on this command.


COMMAND SUMMARY
thi s co mmand to change th e date (a ltho ugh it w ill
not update the BIOS; thi s Illu st be done with th e
BIO S's se tup utility ).

While there are literally hundreds of" commands
available in Linux , the following arc some of the
more common and important :
o

cal - displays a cal e ndar on the screen. With no
arguments, displays a calendar for the current
month . Optionally, a year may be specified.
which will display a calendar for the entire year.
or a month and year may be given as arguments ,
displaying the specified month 's calendar. If
specified, the month must be a number between
one and 12 and must precede the year, which can
be from I - 9999.

o

r

o
o

cat - di splays the contents of the file to the
screen. Designed to display textual data only. If
there is more information than will fit on a

screen, it simply scrolls ofT the screen. To display
only a screenful of information at a time, use the

commands less and more, as described below.

o

di sk space o n a ll partiti ons o r o n a spcc ified par­
tition (in I K blocks by de fault ). l3y using th e-i
option , the number of free in odes (direct ory
entri es) may be di splayed inst ead .
o

du - this cOlllmand will repo rt the used di sk
space for the speci ri ed directo ry (thc default is
the current directory) und each of it s subdirect o­
ries. The numbers give n are in I KH bl oc ks by
default. Using the -a option will report disk uti­
li zation informati o n o n all fil es in eac h directory
as well. The -c opti o n will di spl ay a g rand to tal
at the end of the output.


o

echo - this command will a llow you to print text
to the screen. It is otten used in shell scripts to
infi.mn the user on the progress 01" the script. It
can also be used to put information in a fil e by
piping the output to a file.


clear - clears the screen.
cp - copies files. The syntax is either cp
<options> <filel> <filel>, which allows you to

o

copy a file to another name (for example, to back
it up), or cp <optiolls> which allows you to copy one or more files to a
different directory. Thi s powerful command
of1'ers many options, of which two are especially
important, -r and -v. The - r switch tells cp to
copy file s recursively, meaning that all of the
matching files from all subdirectories will also
be copiecl. For example , the command "cp - r *
Ibackup" will copy all files in the current subdi­
rectory, and all subdirectories below the current
subdirectory, to the fbackup directory. The -v
option stands for "verbose," which will display
the file name(s) on the screen as they are copied.

o

cut - this very useful , very specialized command

o

date - displays the current date (optionally in a
format you specify). The root user may also use


free - displays stat istics on memory utili za tion
in the following categori es: free , used, in stall ed
phy sical memory, and swap space (virtual me m­
ory). among others. T he sizes arc in KI3. unless
the -m switch is used to di splay the o utput
in MH.

o

fsck - the file system checker utility w ill ve ri fy
a fil e system 's integrity. optionally attcmpting to
repair any problems it di scovcrs. It is s imilar to
CI-IKDSK or ScanDisk in the DOSfWindows
world. T his happens by default each time the
system is booted. Thi s cOlllmand is des igned tc>r
adm inistrators.

will allow you to remove a column (field) from a
fil e. You specify the columns (in absolute posi­
tions or by field number) to keep; the rest are dis­
carded. See also paste.
o

df - thi s command will report the am ount o fF ee

head - di splays th e first few (10 by

dcl~lUlt.


unless changed with the - 0 switch) lin es o f the
specified filc( s ). Olien used to review e rror logs
and with other file s where the most important
information is at the top of the file. Sec al so tail.
o

hostname - displays the current host name
(with -s), domain name (with -d) , or both (with


Command Summar (continued)
-I" to di splay the FQDN : Fully Qualified Domain
Name) . The IP addressees) may be displayed instead
by using the - i option.

• nslookup - this tool allows you to query DN S for
FQDN s. For example, querying DNS with the com­
mand "nslookup www.redhat.com.. will return the IP
addressees) for www.redhat.com.

• tee ­ takes output destined fo r the screen and sends
it to both the screen and a specified fil e; useful to 'cc
thc output of a command and to save that output for
later usc as well.

• id - displays your user ID and group lO(s). It can

show your cOcctive uscr and group ID(s) if you su
to anothcr user (scc su).


• paste - merges files into multiple columns in a single

file. See also cut.

• ifconfig - the interface con fig command allows
you to view, and optionally change, TCP/ IP-related
information. The information is generally set at boot
and viewed afierwards. Without any arguments, it
will display the IP-related information for a
machine, including IP address, subnetmask, and so
on. Used primarily by administrators.

• ping - allows you to send packets to a destination and,
if the destination host is online and available, receive
replies. In this respect, it is similar to sonar. By default,
a packet will be sent every second until the command is
stopped by pressing <Ctrl><c>, unless the -c switch is

specified along with the number of packets to send. This

is one of the most basic, and most used, diagnostic com­
mands available for testing network connectivity.

• telnet - allows you to access a remote system and
perform commands as ir you lVere on th e rcmote
system. As all information (inc luding pa sswords)
is sent as clear text, encryption should be consid­
ered or another application , such as SS II (secure
shell), should be used to protect important data
and password s.


• init - used when the system starts to initialize. May

also be used after boot to start and stop various
groups of services. While the levels vary from dis­
tribution to distribution , several are widely used,
including:
• 0 - halt (shutdown) the system
• 1 - place the system in single-user mode (typi ­
cally done by administrators while performing
maintenance)
• 3 - multi-user mode, without the GUI started
(normal level for servers)
• 5 - multi-user mode, GU I started (normal level
for user workstations)
• 6 - rcboO! the machine (same as level 0, with a
reboot at the end)
• less - the less command allows you to scroll
through data, searching for values, moving up and
down through the data . T he less command is far
more powerful than the more comm and (described
below); hencc, you will often hear "leIs is more." It
offers many command line options, as well as many
command s once the file is displayed. View the man
pages for information on all of them . A few of the
most important commands that can be used while
the file is displayed are:
• <space> or f - scroll forward one screenful
• <return> or e or j - scroll forward one linc
b - scroll back one screcnful

• y or,k - scroll back one line
' - search forward for pal/em
• 7 - search back ward for pat/em
• n - search in the same direction for pattem as the
last search
• N - search in the opposite direction for pattern as
the last search
• q or :q or ZZ - exit less and return to a com­
mand prompt
• In - creatcs a link (or alias) to a file, creating two
dircctory entries that point to the same file on disk .

Similar in purpose to a shortcut in Windows.
• more - the more command allows you to scroll
through a file by line or screenful. There are far
fewer options than with less, but all of the options
listed above for less work except for the following:
e, j, y, k, '!, N, :q, and ZZ.
• mount -this command will show all of the mount­
ed devices and/or allow you to mount new devices.
If you want to mount a new device, you need to
specify the device and the directory to which the
device is to be mounted. You can mount
Linux/ Minix/UNIX, OS/2, DOS, and C D-ROM
(ISO 9660) file systems, among others. This com­

mand is only available to the root user.

~


z

~

• rm - allows you to remove (delete) a file or directory.
You must have at least write permissions to the directo­
Iy to be able to remove any files. but write permission s
to the files are 110t required . If you don't have write per­
mission to a file, you will be prompted whether to
remove it anyway. If used with the -r option and a
directory name is specified, all files in that directory
and all subdirectories will be deleted, as will the subdi ­
rectories and the directory itsel f. This is a very power­
ful command when used with the - r option, so be very

careful when usin g it.

• rmdir - removes the specified directory or directori es,
but not the contents of the directory. See also rm .
• shutdown - shuts down the system , by taking it to

run level I (sec init for more information on the diflc r­

ent levels). T he shutdown can be immediate by specify ­
ing " now," a number of minutes in thc future (by spec­

ifying +11 , where 11 is the number of minutes to wait ), or

at a given time, by specifying the time in /lh : ///I11 for­
mat. A message (optionally user-specified) will be sent

to a ll users currently logged on to the system , telling
them to logoff before the system goes down, and the
Illessagc is repeated at a fa ster and faster rate as the
specified time nears . The system can be compl etely
shutdown (vs. run level I) by using the - h switch,
rebooted with the - r switch, or an impending shutdown
can be canceled with th e -c switch. Only root can use
this command.
• sort - allows you to sort a file, line by line. Useful in
sorting output, from other commands, that is displayed
in an un sorted order or an order that is not des ired.
Often used with uniq (described in this sUlllmary) to
view unique lines or words only.
• su - allows you to assume another user's user and

group identities. Most, but not all, programs act based
on a user's effective user and group IDs, which mayor
Illay not be the actual user ID that was originally logged

in. For all users other than root, a password must be

specified for the given user. If 110 user is spc ifiecl root

is assumcd. This is a great utility for administrators and
programmers to see how the system or an appl ication
bchaves when logged in as a normal user instead of the
more powerful user that they may normally usc. Thi s is
also useful for allowing administrators to login as nor­
mal users, only gaining root access as needed, mini­


mizing the chances of accidentally causing maj or Sys­

iem disruptions.

• mv - allows you to move and rename files and
directories.

• tac - this cOlllmand is the cOlllmand cat spelled bac k­
wards and, as the spelling would suggeSt, displays the
spccified file backwards (line by lin~), starting at the
end and finishing with the beginning.

• netstat - displays TCP/IP information for all
active sockets (TCP and UDP), including the port
numbers and the number of bytes waiting to be both
sent and received.

• tail - displays the last few ( 10 by default; change the
number with the -II option) lincs of a file. Often used

to display error and activity logs that place the most

recent information at the end of the file . See al so head.


CREDITS
Author: John Hales
Layout: Michael D. Adam

D.- - - - - - ­


=
~

• reboot - this command will close a ll files, terminate

all processes, shutdown the system, then reboot it.

free
wn~adS
& at
nLJ nd~re
01. titles

ISBN-13:
ISBN-10:

qUlc 5 uuy.com

• touch - used to update the la st access and last mod­
ification date and timcs lor the files specified to the
current date and time . Useful with comm ands th at act
based on th e informati on in the last-accessed or last­
modified field s, such as backup applicati ons.
• traceroute - shows t he route a packet takcs from
it s place of origin to its destination host via each
router. Useful in determining the best rout e to a given
destinati on, as wcll as giv ing informati on on cl ogged
routes (as it reports th e tim e spent at eac h router).
• unmount - thi s is the oppos ite o f the mOll nt com­

mand and will , there fore, unmoun t a previously
mounted fil esystem.
• uniq - removes dupli cate adjacl'l/ t lines fro m a file,
sending the output to the screc n or a fiic. Us ually used
with sort to en sure the data is presorted. The -c
switch will print eac h lin c and di splay the number of
times it occ urs .
• uptime - d isplays th e current time, the Ic ngth of
time the uscr has bcen logged in , how many users are
currently logged in, and information on system utiliza­
tion over the last 1-,5-, and 15- minute intcnals.
• wc - di splays a cha racter, word, and Iinc count fo r the
speei ficd fil e(s) or standard inp ut. O ft en, the output
o f other co mm ands is piped in to we to get this infor­
mation in combi na tion with those commands.
• who - by defa ul t, thi s com ma nd with no options
will di splay a li st of a ll o f the users cu rrently
logged in , where they logged in fro m, and the ti me
th ey logged in . When used w ith the - i option, it
will also di splay th e amo unt of id le time, " hich
can be use ful in dete rmining who is us ing the systcm
without logging 00' when fini shed. One of the most
uscful swit ches is - h, whi ch will acid co lum n head­
ings to the output.
• whoami - di splays the current use r's user name.
T his information can also he obtained by usc of
option s assoc iated with the id and who cOlllmand s.
man 8r info
Help is available for almost all
commands, displaying all com­

mand options. listing related commands, and so on. The main source
of help is the man pages. The syntax is simply "man
<t:ommand>." For example, to view the man pages

on grep. type "man grep:' To, iew a list of available
commands with a brief description of each, type
"man -k keyword:' Many commands now have
more extensive documentation available on the info
pages. To view the info pages. simply type "info
<£"Ommand>:' Many distributions also include help
in a graphical format as well.


978-157222448 - 3
157222448-7

PRICE

911~ lllJllll ~IIIJIJI!I!llIJllllflllllfIlillll

Customer Hotline # 1.800.230.9522

U.s. $ 5.95
CAN $ 8.95

Screen representations may vary depending on the version of the software that is installed. This guide is based
on the software version that was shipping at the time of publication and is accurate to that version. For specific
changes to a software application, see the Read-Me file provided with the software application.
All rights r('sernd. No part of this rub li..::niol1 may be rcprod u..:cd or Iran~rn ;\\L'd; l1 :my form. or by any m c[m~. ci..:C\ronic or
alld relriL'val system. without writlcil perm issioll fm m Ille puhl isher. C ZOO I BarCharts. Inc. Boca Raton, FL 0408



Ill c l.:h ~ nicaL

incl udi ng ph()llX~ ()PY, r..ocorJillg. or rilly inii'll"Infn;OI1 ~ t ora g('


6

6

LU2lft

6