Sie sind auf Seite 1von 13

Learn UNIX in 10 minutes.

Fundamentals of UNIX
Description: Fundamentals of UNIX teaches you how to use UNIX operating
system commands and, in the hands-on exercises, basic un !icrosystems"
olaris #! operating en$ironment commands, and introduces you to the
%ommon &es'top (n$ironment )%&( - graphical interface between different
en$ironments*+ #he class is intended for new users of UNIX+ ,ou will learn
fundamental command-line features of the olaris en$ironment including file
system na$igation, file permissions, the $i text editor, command shells and basic
networ' use+ %&( features include tandard &es'top #ools, #ext (ditor, printing
and mail+

Commands
Archives and Storage
compress
used to compress files
tar
"tape archive"; create archives, and read/write from tapes
and diskettes
File Management
cat
"concatenate"; used to display files, or concatenate files
cd
"change directory"
cp
"copy"; used to copy files and directories
file
used to determine a file's "type"
ls
"list"; list files and directories
mkdir
"make directory"; used to create new directories
more
control the display of files (one screenful at a time)
mv
"move"; used to move files and directories
pwd
"print working directory"
rm
"remove"; used to remove files and directories
wc
"word count"; used to count characters, words, and lines in text
files and/or standard input
Printing
cancel
used to cancel print requests
lp
"line printer"; used to sumit print !os
lpstat
"line printer statistics"; used to display information aout
printer queues
Searching
find
a powerful command used to find files and directories with a
wealth of search criteria
grep
"general regular expression parser"; would e etter named
"search" or "textsearch"
System Status
df
"disk free"; used to show information aout free disk space on
filesystems
du
"disk usage"; most often used to determine the si"e of directories
ps
"process statistics"; used to show the processes currently running
on the system
who
used to show who is logged in
Text Processing
grep
"general regular expression parser"; would e etter named
"search" or "textsearch"
sort
used to sort information provided on standard input
Preface
This is something that I have given out for new unix
admins. The purpose is to have on one page the basics to
get started using the UNIX command line
Sections:
Directories:
Moving around the file system:
Listing directory contents:
Changing file permissions and attributes
Moving, renaming, and copying files:
Viewing and editing files:
Shells
nvironment variables
!nteractive "istory
#ilename Completion
$ash is the way cool shell%
&edirection:
Pipes:
Command Substitution
Searching for strings in files: 'he grep command
Searching for files : 'he find command
&eading and writing tapes, bac(ups, and archives: 'he tar
command
#ile compression: compress , gzip , and bzip2
Loo(ing for help: 'he man command
$asics of the vi editor
#)*s
***********************************************************
*******************************
asic UNIX !ommand "ine #shell$ navigation % "ast
revised &a' () *++(
***********************************************************
*******************************
Directories:
,ile and director' paths in UNIX use the forward slash -.-
to separate director' names in a path.
examples%
. -root- director'
.usr director' usr #sub/director' of . -root-
director'$
.usr.0T1I&(++ 0T1I&(++ is a subdirector' of .usr
Moving around the file system:
pwd 0how the -present working director'-2 or
current director'.
cd !hange current director' to 'our 34&5
director'.
cd .usr.0T1I&(++ !hange current director' to .usr.0T1I&(++.
cd INIT !hange current director' to INIT which is
a sub/director' of the current
director'.
cd .. !hange current director' to the parent
director' of the current director'.
cd 60T1&7418 !hange current director' to the director'
defined b' the environment
variable
90T1&74189.
Listing directory contents:
ls list a director'
ls /l list a director' in long # detailed $ format
for example%
6 ls /l
drwxr/xr/x : cliff user (+*: ;un (< +=%:+
7>IT14N?5>1NIN@0
/rw/r//r// ( cliff user )A)B=* ;un A (:%*<
scanlib.tar.gC
D D D D D D D D D D D
E E E E E E E E E E E
E E E E E owner group siCe date time
name
E E E E number of links to file or director' contents
E E E permissions for world
E E permissions for members of group
E permissions for owner of file% r F read2 w F write2 x F
execute /Fno permission
t'pe of file% / F normal file2 dFdirector'2 l F s'mbolic
link2 and others...
ls /a "ist the current director' including hidden
files. 3idden files start with -.-
ls /ld * "ist all the file and director' names in
the current director'. 7ithout the -d-
option2 ls would list the contents of an'
sub/director' of the current. 7ith the -d-
option2 ls Gust lists them like regular
files.
Changing file permissions and attributes
chmod )HH file !hanges the permissions of file to be
rwx for the owner2 and rx for
the group and the world. #) F rwx F
((( binar'. H F r/x F (+( binar'$
chgrp user file &akes file belong to the group user.
chown cliff file &akes cliff the owner of file.
chown /1 cliff dir &akes cliff the owner of dir and
ever'thing in its director' tree.
Iou must be the owner of the file.director' or be root
before 'ou can do an' of these things.
Moving, renaming, and copying files:
cp file( file* cop' a file
mv file( renamed file( move or rename a file
rm file( Jfile* ...K remove or delete a file
rm /r dir( Jdir*...K recursivl' remove a director' and
its contents 5 !>15,U"L
mkdir dir( Jdir*...K make a director'
rmdir dir( Jdir*...K remove an empt' director'
Viewing and editing files:
cat filename Mump a file to the screen in ascii.
more filename Nrogressivel' dump a file to the screen%
5NT51 F one line down
0N>!5>1 F page down OFOuit
less filename "ike more2 but 'ou can use Nage/Up too.
Not on all s'stems.
vi filename 5dit a file using the vi editor. >ll UNIX
s'stems will have vi in some form.
emacs filename 5dit a file using the emacs editor. Not
all s'stems will have emacs.
head filename 0how the first few lines of a file.
head /n filename 0how the first n lines of a file.
tail filename 0how the last few lines of a file.
tail /n filename 0how the last n lines of a file.
Shells
The behavior of the command line interface will differ
slightl' depending on the shell program that is being used.
Mepending on the shell used2 some extra behaviors can be
Ouite nift'.
Iou can find out what shell 'ou are using b' the command%
Pprintenv 035""
4f course 'ou can create a file with a list of shell
commands and execute it like a program to perform a task.
This is called a shell script.
This is in fact the primar' purpose of most shells2 not the
interactive command line behavior.
nvironment variables
Iou can teach 'our shell to remember things for later using
environment variables.
,or example under bash%
export !>0144TF.usr.local.!>0B.+ Mefines the
variable !>0144T with the value

.usr.local.!>0B.+.
cd 6!>0144T !hanges 'our
present working director' to the value of !>0144T
export "M?"I1>1I?N>T3F6!>0144T."inux.lib
Mefines the variable "M?"I1>1I?N>T3 with the value of
!>0144T with ."inux.lib appended2 or
.usr.local.!>0B.+."inux.lib
printenv !>0144T 7ill print out the value of
!>0144T2 or .usr.local.!>0B.+
echo 6!>0144T Moes exactl' the same thing
env E grep !>0144T > roundabout wa' to get the same
information.
!nteractive "istory
> feature of bash and tcsh #and sometimes others$ 'ou can
use
the up/arrow ke's to access 'our previous commands2 edit
them2 and re/execute them.
i
#ilename Completion
> feature of bash and tcsh #and possibl' others$ 'ou can
use the
T> ke' to complete a partiall' t'ped filename. ,or example
if 'ou
have a file called constantine/monks/and/will'/wonka.txt in
'our
director' and want to edit it 'ou can t'pe 9vi const92 hit
the T> ke'2
and the shell will fill in the rest of the name for 'ou
#provided the
completion is uniOue$.
$ash is the way cool shell%
ash will even complete the name of commands and
environment variables.
>nd if there are multiple completions2 if 'ou hit T> twice
bash will show
'ou all the completions. ash is the default user shell for
most "inux s'stems.
&edirection:
grep string filename Q newfile
1edirects the output of the above
grep command to a file 9newfile9.
grep string filename QQ existfile
>ppends the output of the grep
command to the end of 9existfile9.
The redirection directives2 Q and QQ can be used on the
output of most commands
to direct their output to a file.
Pipes:
The pipe s'mbol -E- is used to direct the output of one
command to the input
of another.
,or example%
ls /l E more This commands takes the output of the long
format director' list command
-ls /l- and pipes it through the more
command #also known as a filter$.
In this case a ver' long list of files can
be viewed a page at a time.
Command Substitution
Iou can use the output of one command as an input to
another command in another wa'
called command substitution. !ommand substitution is
invoked when b' enclosing the
substituted command in backwards single Ouotes. ,or example%
cat Rfind . /name aaa.txtR
which will cat # dump to the screen $ all the files named
aaa.txt that exist in the current
director' or in an' subdirector' tree.
Searching for strings in files: 'he grep command
grep string filename prints all the lines in a file that
contain the string
Searching for files : 'he find command
find search?path /name filename
find . /name aaa.txt ,inds all the files named aaa.txt
in the current director' or
an' subdirector' tree.
find . /name vimrc ,ind all the files named 9vimrc9
an'where on the s'stem.
find .usr.local.games /name -*xpilot*-
,ind all files whose names contain
the string 9xpilot9 which
exist within the 9.usr.local.games9
director' tree.
&eading and writing tapes, bac(ups, and archives: 'he tar
command
The tar command stands for -tape archive-. It is the
-standard- wa' to read
and write archives #collections of files and whole
director' trees$.
4ften 'ou will find archives of stuff with names like
stuff.tar2 or stuff.tar.gC. This
is stuff in a tar archive2 and stuff in a tar archive which
has been compressed using the
gCip compression program respectivl'.
!hances are that if someone gives 'ou a tape written on a
UNIX s'stem2 it will be in tar format2
and 'ou will use tar #and 'our tape drive$ to read it.
"ikewise2 if 'ou want to write a tape to give to someone
else2 'ou should probabl' use
tar as well.
Tar examples%
tar xv 5xtracts #x$ files from the default tape drive
while listing #v F verbose$
the file names to the screen.
tar tv "ists the files from the default tape device
without extracting them.
tar cv file( file*
7rite files 9file(9 and 9file*9 to the default
tape device.
tar cvf archive.tar file( Jfile*...K
!reate a tar archive as a file -archive.tar-
containing file(2
file*...etc.
tar xvf archive.tar extract from the archive file
tar cvfC archive.tar.gC dname
!reate a gCip compressed tar archive containing
ever'thing in the director'
9dname9. This does not work with all versions
of tar.
tar xvfC archive.tar.gC
5xtract a gCip compressed tar archive. Moes
not work with all versions of tar.
tar cvfI archive.tar.bC* dname
!reate a bC* compressed tar archive. Moes not
work with all versions of tar
#ile compression: compress , gzip , and bzip2
The standard UNIX compression commands are compress and
uncompress. !ompressed files have
a suffix .S added to their name. ,or example%
compress part.igs !reates a compressed file part.igs.S
uncompress part.igs Uncompresseis part.igs from the
compressed file part.igs.S.
Note the .S is not reOuired.
>nother common compression utilit' is gCip #and gunCip$.
These are the @NU compress and
uncompress utilities. gCip usuall' gives better
compression than standard compress2
but ma' not be installed on all s'stems. The suffix for
gCipped files is .gC
gCip part.igs !reates a compressed file part.igs.gC
gunCip part.igs 5xtracts the original file from
part.igs.gC
The bCip* utilit' has #in general$ even better compression
than gCip2 but at the cost of longer
times to compress and uncompress the files. It is not as
common a utilit' as gCip2 but is
becoming more generall' available.
bCip* part.igs !reate a compressed Iges file
part.igs.bC*
bunCip* part.igs.bC* Uncompress the compressed iges file.
Loo(ing for help: 'he man command
&ost of the commands have a manual page which give
sometimes useful2 often more or less
detailed2 sometimes cr'ptic and unfathomable discriptions
of their usage. 0ome sa' the'
are called man pages because the' are onl' for real men.
5xample%
man ls 0hows the manual page for the ls command
$asics of the vi editor
4pening a file
vi filename
!reating text
i Insert before current cursor position
I Insert at beginning of current line
a Insert #append$ after current cursor position
> >ppend to end of line
r 1eplace ( character
1 1eplace mode
T50!Q Terminate insertion or overwrite mode
Meletion of text
x Melete single character
dd Melete current line and put in buffer
ndd Melete n lines #n is a number$ and put them in buffer
; >ttaches the next line to the end of the current line
#deletes carriage return$.
4ops
u Undo last command
cut and paste
'' Iank current line into buffer
n'' Iank n lines into buffer
p Nut the contents of the buffer after the current line
N Nut the contents of the buffer before the current line
cursor positioning
Dd Nage down
Du Nage up
%n Nosition cursor at line n
%6 Nosition cursor at end of file
Dg Mispla' current line number
h2G2k2l "eft2Mown2Up2 and 1ight respectivl'. Iour arrow
ke's should also work if
if 'our ke'board mappings are an'where near sane.
string substitution
%n(2n*%s.string(.string*.JgK 0ubstitute string* for
string( on lines
n( to n*. If g is
included #global$2
all instances of string(
on each line
are substituted. If g is
not included2
onl' the first instance
per line is
substituted.
D matches start of line
. matches an' single character
6 matches end of line
These and other -special characters- #like the forward
slash$ can be -escaped- with U
i.e to match the string -.usr.0T1I&(++.04,T- sa'
-U.usrU.0T1I&(++U.04,T-
5xamples%
%(26%s.dog.cat.g 0ubstitute 9cat9 for
9dog92 ever' instance
for the entire file /
lines ( to 6 #end of file$
%*B2*H%.frog.bird. 0ubstitute 9bird9 for
9frog9 on lines
*B through *H. 4nl' the
first instance
on each line is
substituted.
0aving and Ouitting and other ex commands
These commands are all prefixed bu touching the colon #%$
and entered in the lower left corner
of the window. Iou cannot enter a ex command when 'ou are
in an edit mode. Touch T50!Q to exit from
an editing mode.
%w 7rite the current file.
%w new.file 7rite the file to the name 9new.file9.
%wL existing.file 4verwrite an existing file with the file
currentl' being edited.
%wO 7rite the file and Ouit.
%O Vuit.
%OL Vuit with no changes.
%e filename 4pen the file 9filename9 for editing.
%set number Turns on line numbering
%set nonumber Turns off line numbering

Das könnte Ihnen auch gefallen