LINUX
A'QUICK'INTRODUCTION
The'Un ix'S ys tem
Unix%is%case%sensitive
Unix%users%do%not%use%spaces%in%filenames%
Most%of%the%work%is%done%from%the%shell
S hell%acts%as%interface%between%user%and%system
Bourne%shell%is%the %shell%used%i n%U nix
echo%$shell
/bin/bash
Login
An%account,%username%a nd%pa ssword%is%required%to%login%to%a%system.
Remote%login%requires%Secure%SHell :%remote%login%program
Allows%you%to%log%on%to%a%remote%machine
S SH%ensures%secure,%encrypted%communication%
Syntax
ssh username@hostname
or
ssh -l%username %hostname
Files'and'Directories
cd%directory% change%to%directory%directory
pwd show%absolute%path%of%current%directory
ls show%all%files%in%current%directory
ls%-a%directory% show%all%files%in%directory%directory (including%filenames%starting%with%.)
ls%-l% show%all%files%in%current%directory%(detailed%file%information)
cat%file% print%content%of%file%file to%STDOUT
more%file% page%through%file%file one%screenful at%a%time
less%file% like%more,%but%more%user%friendly
cat%f1%f2%>f3% write%content%of%file%f1%and%f2%to%file%f3
cat%f1%>>f2% append%content%of%file%f1%to%the%end%of%file%f2
cp f1%f2% copy%file1%to%file2%(rename%f1%as%f2)
cp f1%f2%directory% copy%files%f1%and%f2%into%directory%directory
mv%f1%f2% rename%file%f1%as%file%f2
mv%f1%dir move%file%f1%to%directory%dir
mkdir directory% make%(create)%directory%directory
rm file% remove%file%file
rmdir directory remove%directory
rm -r%dir remove%directory%dir and%all%files/directory%in%dir
text-editor-name%file open%file%file in%text%editor
*Text%Editors%– vi,%gedit (has%a%GUI),%emacs,%xemacs,%pico,%nano
File'Sy s tem'Permissions
File%system%permissions %unde r %U NIX/Linux:
Øfiles/directories%are%owned%by%a%user%who%b e lon g s%to%a%specific%group
Øpermission%to%read/write/execute%can%be%defined%independently%for%specific%users%and%groups
Øto%start/delete%a%file%you%need%write/ex ecute%permission%for%the%directory
Øto%list%the%content%of%a%directory%(ls),%you%need %the%permission%to%read/execute
user' group' other
- r%w%x% r%w%- r%- x% file
d% r%w%x% r%w%x% r%- x% directory
File'Sy s tem'Permissions
ls%
-l%file
show%detailed%file%info%for%file%
file
ll
same%as%ls%
-l%
chmod
u+x file
set%permission%to%execute%file%for%user%
(means%user%is%allowed%to%execute%file)
chmod
o+r file
set%reading%permission%for%other%
(means%file%can%be%read%by%all%users)
chmod
g+w file
set%writing%permission%for%group
chmod
754%file
user%is%allowed%to%read/write/execute%file%
group%is%allowed%to%read/execute%file%
other%is%allowed%to%read% file
chown
user%file
change%owner%of%file%to%user%
e.g.%
chown math%file% file %is%owned%by%math%now
chown
user%file
change%group%of%file%to%group
Mor e'use ful'Commands
who
show%who%is%currently%logged%in%to%the%system%
which%command
show%path%for%a%(shell)%command
locate%pattern%
find%all%files%in%a%database%which%match%the%pattern
man%command
show%
manpages (manual)%for%a%command%
command%
- -help
show%help%for%command
command%
-h
same%as%command%
- -help
head%file
print%first%10%lines%of%file%
file to%STDOUT%
head%
-100%file
print%first%100%lines%of%file%
file to%STDOUT%
tail%file
print%last%10%lines%of%file%
file to%STDOUT%
tail%
-50%file
print%last%50%lines%of%file%
file to%STDOUT%
cat%file
print%content%of%file%to%STDOUT
df
print%available%and%used%disk%space%usage%of%file%system
du
print
estimate%of%file%space%usage
Wildcards
Asterisk%*
match es%any%number% o f%characters,%including%non e
Square%brackets%[3
-9]
any%number%between%3%and%9%
Square%brackets%[c
-f]
c,%d,%e%or%f
ls%*.txt
list%all%file%name s% ending%with %.txt
mv%handout*%WS09
move%all%files%starting%with%“handout”%to%directory%WS09%
rm
chapter[2-5]
delete
chapter2,%chapter3,%chapter4,%chapter5
ls%*.[
pt][dx][ft]
list%all%files%ending%with%.p df%and%.txt%
cp
*.htm*%directory
copy%all%files%ending%with%.
htm,%followed%by%any%number%of%ch aracters,%including%
none,%to%directory%e. g .% f ile.htm,%file.html%
cp *.htm?%directory%copy%all%files%ending%
with
cp
*.htm?%directory
copy%all%files%ending%with%.
htm,%followed%by%exactly%one %character,%to%directory%
file.html%(but%NOT%file.htm)
Grep
grep%pattern%file
prints%all%lines%in%file%matching%a%particular%search%pattern
grep%crisis%file
prints%all%lines%in%file%containing%“crisis”
grep%
-v%crisis%file
prints%all%lines%in%file%NOT%containing%“crisis”
grep%
-o%crisis%file
show%only%the%part%of%the%line%that%matches%“crisis”%
grep%[Mm]inister[Ii]*n*%file
show%all%lines%containing%the %masculine%or%feminine%form%of%“Minister,%and%
all%compound%words%with%“minister”%
grep%
-n%pattern%file
include% line%numb e rs%
grep%
- -color%pattern%file
highlighting%of%search%pattern%
grep%pattern%file%|%
wc -l
shows%number%of%lines%containing%search%patt ern%(How%often%occurs%pattern%
in%file?)%
Find
find
.%-name%filename
by%name%(case%- sensitive)
find
/directory -name%filename
filename%under% the%directory%directory
find
.%-name%‘filena
file%with%partial%filename
find
~%-iname ‘*.tex
by%name%ignoring%the%case%(~%used%for%including%hidden%
find
~%-size%+50M%
all%files%greater%than%50MB
find
~%-size%-100M
all%the%files%le ss%than%100MB
find%
.% type%f%%name%“*.py
all%the%files%with% ending% .py
find
/home% -user%math
by%a%particular%user
File'Trans fer
While%working%on%a%remote%system%use%the %following%for%file%transfer:
sftp
sftp
p%port%username@host
scp
scp
username@remotehost.edu:%foobar.txt%/some/local/directory
rsync
rsync
options%source%d e stination
ssh
with%remote %display
Ssh
X%or%ssh –Y (XII%forwarding)
Compressing/Archivi ng'File s
file%endings
tar.gz,%
tgz,%zip,%gz,%bz,%rar,%bz2,%...%
gzip
file
compress%a%file%using%
gunzip
gunzip
file.gz
uncompress
a%gunzip file
tar%
-cf archive.tar%f1%f2%f3
create%archive%archive.tar%and%add%files%f1,%f2,%f3%to%archive%file
tar%
-czf archive.tgz%f1%f2%f3
like%tar%
-cf,%additionally%compress%archive%using%gunzip
tar%
-xzf archive.tgz
decompress%archive.tgz%and%write%files%to%current%directory
tar
jxf archive.bz2
unpack%.bz2
file
tar%
jcf archive.bz2 f1%f2%f3
create %.bz2
archive%file
zip%zipped.zip%f1% f2%f3%
create
.zip%compressed%files
unzip%zipped.zip
unzip
a%.zip%file
Job'Control
jobs list%all%jobs%(running%processes)%
jobs%-l jobs%with%job%id%
ps show%all%running%jobs
kill send%signal%to%job
kill%-l lists%all%possible%signals
kill%-9%PID send%signal%SIGKILL%(terminate%process)%to%job%with%id%PID%
<STRG>-c terminate%current%job
<STRG>-z suspend%current%job
bg resume%suspended%job%in%the%background%
bg job%number resume%job%with%job%number%in%the%background%
fg job%number resume%job%with%job%number%in%the%foreground
command%& start%command%in%the%background%
pipe%%(%| )%%commands send the output of one program to another program for further processing.
cat filename%|%less display%the%contents%of%file%filename%one%screenful at%a%a%time%using%less
top
show the current processes on the system
./a.out execute%command%for%current%directory
Use ful'Link s
Linux%Shell%Scripting%Tutorial%v1.05r3
A%Beginners%handbook
http://www.freeos.com/guides/lsst
The%Linux%Cookbook:%Tips%and%Techniques%for%Everyday%Use
http://dsl.org/cookbook/cookbook_toc.html
Analyzing%Text
http://dsl.org/cookbook/cookbook_16.html
Introduction%to%Linux% A%Hands%on%Guide
tldp.org/LDP/intro-linux/intro-linux.pdf