Sunteți pe pagina 1din 13

La baz este !

Curs UNIX de la Popescu STC


! LINUX Command line Shotts.pdf
C n Linux http://stackoverflow.com/questions/9795693/linux-c-programmingreference
PROGRAMARE C nu CPP Linux IBM compiler.pdf
http://www.tutorialspoint.com/cprogramming/c_file_io.htm

cd

Change current directory


chgrp

Change the owner of a file (limited user)


chmod

Change the access limitations of a file


chown

Change the owner of a file


cksum

Get the checksum of a file


cp

Copy a file from one place to another


df

Calculate the disk free space


du

Calculate the disk usage


env

Display enviroment variables


file

Determine the file type


fuser

Shows which processes are using a specified file


ls

List files
mkdir

Create a directory
pwd

Show the current directory


rm

Delete files/folders
rmdir

Delete an empty directory


uptime

Displays the uptime for the server


Programele centrale kernel, programele de comunicar cu util, shell.
alias, pot redenumi o comand
Program care ruleaz n foregrand: se oprete pe durata fiului.

Cale absolut: ncepe cu / ex /d/user1/tom/keep


Director curent . director printe ..
subdirector ./alfa
home directory ~ (nu toate shell-urile)
case sensitive
Variabile locale aparin doar shell/ului curent, nu se trec la alte proc
litere mici
Variabilele globale se trec de la printe la fiu, dar nu de la fiu la printe litere mari
home directory (HOME), the path (PATH), the current directory (PWD),
the shell (SHELL), and the terminal type (TERM).
Cutarea n PATH. Se caut n ordinea: alias (porecled date comenzilor) comenzi
incluse n UNIX PATH. Dac se indic o cale, nu se mai folosete path.
comand opiuni argumente
CTRL-U cancel comand
Pot fi mai multe comenzi pe linie, separate de ;
Comanda se continu cu \
Dup #, comentarii
Comand n background = comand &
comand > fisier
append: comand >> fisier
pipeline comand1 | comand2
<fisiere, redirectare sa se preia comenzie nu de la input, ci din fiier
Pentru ca s se indice n script s se preia intrrile din acel script se folosete
terminatorul <<terminator
Ex
comand <<EOD
Aici este textul care trebuie interpretat de comand
EOD
If terminatorul is preceded by a backslash (\) this has a special meaning: variables
beginning with $ in the input data are not treated as shell variables.
Help
man k cuvnt
info, uneori

caut helpurile care conin cuvntul

Controlul proceselor i a ecranului


Stty poate schimba funciile apelate cu ctrl.
Se afl funciile cu stty a

Ctrl-c Kill foreground process


Ctrl-z Suspend foreground process
Ctrl-d Terminate input, or exit shell
Ctrl-s

Suspend output

Ctrl-q Resume output

Ctrl-o Discard output


Ctrl-l

Clear screen

TAB completeaz comanda


CTRL-D listeaz fiierele cu nume asemntor

Operator

Function

<

Redirect standard input from file

<<

Redirect standard input from command source

>

Redirect standard output to file

>!

Redirect standard output and overwrite file

>>

Redirect standard output and append to file

>>!

Redirect standard output to file or append to file

>&

Redirect standard output/error to file

>>&

Redirect standard output/error and append to file

>>&!

Redirect standard output/error to file or append to file

Pipe standard output to standard input

|&

Pipe standard output/error to standard input

`command`

Replace command with its output

Comenzi echivalemte MS-DOS

DOS command

Unix command

Function

help []

man [] {}

Provide information about command

chkdsk []

df []

Show disk space

dir/w []

ls []

Wide directory listing

dir []

ll []

Long directory listing

dir/o:-d []

ll -t []

Ditto in reverse creation order

dir/s []

ll -R []

Recursive long listing

dir/p/s []

ll -R [] | more

Ditto with pausing

cd

pwd

Show current directory

cd {}

cd {}

Change directory

cd ..

cd ..

Change to parent directory

cd \

cd

Change to home directory

md {}

mkdir {}

Create empty directory

rd {}

rmdir {}

Delete empty directory

type {}

cat [] []

List file(s)

type {} | more

more {} []

Ditto with pausing

tv {}

less {} []

Ditto

copy {} {}

cp {} {}

Copy file

rename {} {}

mv {} {}

Rename file

move {} {}

mv {} {}

Move file

sort {}

sort {}

Sort file

edit {}

emacs {}&

Edit file

del {}

rm {} []

Delete file(s)

del/p {}

rm -i {} []

Ditto with confirmation

deltree {}

rm -r {}

Recursive delete directory

pkzip {}

gzip {}

Compress file(s)

pkunzip {}

gunzip {}

Decompress file(s)

msbackup []

tar cv .

Make backup

msbackup []

tar xv

Restore from backup

attrib {} {}

chmod {} {}

Change file attribute(s)

fc {} {}

diff {} {}

List file differences

find "{}" {}

grep {} {}

Search file(s) for character(s)

print {}

lpr -P{} []

Print file

print

lpq -P{}

List printer queue

print/c

lprm -P{} {}

Delete print job

doskey/h

history

Show command history

doskey {}={}

alias {} {}

Create command alias

set

set

Show local variables

set {}={}

set {}={}

Set local variable

path

echo $PATH

Show executable path

path {}

setenv PATH {}

Set executable path

for {} {}

foreach {} {}

Loop command

command

tcsh []

Start child shell

{} []

{} []

Run program or script

rem []

# []

Use comment in script

echo {}

echo {}

Display message in script

if {} {}

if {} {}

Conditional command

goto {}

goto {}

Jump to label in script

cls

Ctrl-l

Clear screen

Ctrl-c

Ctrl-c

Kill foreground process

Ctrl-z

Ctrl-d

Signal end of input

Pause

Ctrl-s

Suspend output to screen

Space

Ctrl-q

Resume output to screen

exit

exit []

Exit from script or shell

Comenzi pentru fiiere file

Unix command

Function

du []

Show disk usage

ln {} {}

Create directory entry (hard link)

ln -s {} {}

Create soft link to file

file {}

Show type of file

which {}

Locate executable file in path

touch {}

Create empty file or change file access time

tee {}

Copy standard input to file and standard output

wc {}

Show file length

head []

List top lines of file

tail []

List bottom lines of file

fgrep {} []

Search file(s) for fixed string

egrep {} []

Search file(s) for extended regular expression

find {} []

Multiple file commands

cut []

Extract columns from file

sed {} []

Edit file in stream mode

awk {} []

Process column data

fold []

Fold long lines in file

paste []

Merge lines of files

zcat []

List compressed file

dd {} {}

Convert file format

od {}

Dump file

nl []

Number lines in file

source {}

Read commands from file

Controlul proceselor

Unix command

Function

yppasswd

Change password

stty

Show or set terminal characteristics

bindkey

Show or set key bindings

alloc

Show memory allocation

limit

Show process limits

limit {} {}

Change process limit

umask {}

Change permission for new files

xargs {} []

Execute command with passed arguments

tr {} {}

Translate character(s)

setenv

Show global variables

setenv {} {}

Set global variable

unset {}

Unset local variable

unsetenv {}

Unset global variable

echo ${}

Show value of variable

nice {} []

Run command at low priority

renice {} {}

Reduce priority of command

Ctrl-z

Suspend foreground process

jobs

List background jobs

ps []

Show process status

bg []

Put job in background

fg []

Put job in foreground

stop {}

Suspend background process or job

kill {}

Signal or kill process or job

batch [] []

Submit command script to batch queue

List logged-in users

sleep []

Wait for time interval

time []

Time a command

while {}

Conditionally execute loop

logout

Terminate current session

Reea

Unix command

Function

finger []

List user information

talk []

Exchange messages with other user

pine

Use e-mail

ftp []

Transfer file(s) via network

telnet []

Remote login via network

rlogin []

Ditto

rsh {} []

Remote shell command via network

rcp {} {}

Copy file(s) via network

Programare: FORTRAN, C, PEARL

ci {}

Check file into revision control

co {}

Check file out of revision control

make []

Update program

f77 {}

Compile Fortran 77 program

fsplit {} Split Fortran source into subroutines


cc {}

Compile C program

c++ {}

Compile C++ program

perl {}

Compile and run Perl program

Unix command

Function

date

Show today's date

cal

Show calendar

bc

Evaluate arithmetic expression(s)

EMACS = editoare de text

Emacs command
Ctrl-h

Function
Get online help (e.g. Ctrl-h t for tutorial)

Ctrl-x Ctrl-f

Open file in new buffer

Ctrl-x Ctrl-s

Save active buffer to existing file

Ctrl-x Ctrl-w

Save active buffer to specified file

Ctrl-x s

Prompt to save changed buffers to their files

Ctrl-x i

Insert another file

Ctrl-x Ctrl-b

List all buffers

Ctrl-x b

Select specified buffer

Ctrl-x k

Kill specified buffer

vi, editor de text

Vi command

Function

:set nu

Show line numbers

:set ic

Ignore case differences when searching

:set ai

Set automatic indent

:set sm

Show matching ( or { with ) or } in insert mode

Up/down arrow

Move up/down 1 line

Left/right arrow

Move left/right 1 character column

0 $

Go to 1st/last column of current line

Enter

Go down to 1st printable character of next line

nw nb

Move right/left n words (1 word if n omitted)

nG

Go to line n (end of file if n omitted)

Ctrl-f Ctrl-b

Page forward/backward 1 screen

Ctrl-d Ctrl-u

Page forward/backward half a screen

[[ ]]

Go to beginning of current/next C function

/expressionEnter

Search forwards for expression

?expressionEnter

Search backwards for expression

n N

Repeat last / or ? command in same/reverse direction

ytarget

Copy (yank) text up to target to buffer

Copy current line to buffer

itextEsc

Insert text before cursor

otextEsc

Open new line below cursor and insert text

Replace character under cursor with next typed

RtextEsc

Replace text

Backspace

In insert mode, delete character before cursor

x X

Delete character under/before cursor

nx

Delete n characters under and to right of cursor

nX

Delete n characters before cursor

dd

Delete current line

ndd

Delete n lines

Delete from cursor to end of line

p P

Put back yanked or deleted text below/above current line

Join current and next lines

:m,n s/old/new/gc

Global replace (g=every occurrence on line, c=prompt)


m=. means from current position, n=$ means to EOF

Undo last change

:q

Quit, provided no changes were made

:q!

Quit without saving

:w

Save (write) changes

:m,n w file

Save lines m through n (default=all) to file

:x

Save changes and quit

Exerciii
# Set variable P to the PDB data directory.
setenv P /public/pdb/data # Do this once for each instance of the shell.

6.1. emacs exercise.


# First copy a file: note the "." at the end!
cp $P/pdb6lyz.pdb . Punctul indic directorul current. Observ c a
concatenate calea cu fiierul.
# ... and the character after "6" is an ell not a one.
# Set mode to write:
chmod +w pdb6lyz.pdb # Don't forget to use filename completion.
# Define display for X application (once per shell):
setenv DISPLAY lundynn:0
# Edit the file in background; note the ampersand (&):
emacs pdb6lyz.pdb&
# You'll find it easier if you make your shell and Emacs windows wider.

Comanda yum = instaleaz i updateaz


#include<stdio.h>
/* demo.c: My first C program on a Linux */
int main(void)
{
printf("Hello! This is a test prgoram.\n");
return 0;
}
cc program-source-code.c -o executable-file-name
g++ demo2.C -o demo2
## or use the following syntax ##
make demo2

Lucrarea 3: sincronizare prin semnale


semnale: situaii neprevzute, mai rar comunicare
nu conine informaie util, conteaz doar tipul.
Procesul care primete semnalul nu tie de la cine l-a primit
Semnalul este o ntrereupere soft. Luarea lui n seam poate fi amnat de procesul
destinatar.
Semnale: erori, evenimente externe, cereri explicite (kill())

Lucrarea nr. 4 Canale pipe fara nume (anonime)


canale de comunicaie, conducte, pipe
Canale unidirecionale, bidirecionale
List ordonat cu utilizatorii cu sesiuni de lucru deschise
who | sort | pr

Pipe prin programare


Se creaz un pipe cu descriptor de fiier pentru citire i scriere.
La el au acces printele i fiul. Deobicei este pentru comunicarea printe-fiu. Dou
fiiere deja create nu pot comunica prin pipe.
SE descriu tehnici de evitarea a blocrilor
O conduct >= 4ko
Descriptorii de fiier se pot duplica sau renoi cu dup() i dup2(). n urma acestor
funcii read() i close() funcioneaz altfel.
n loc de a se comunica printr-un pipe bidirecional, mai bine se folosesc dou pipe
unidirecionale.
Exemplu de comunicare cu blocarea comunicrii deoarece nu este sincronizare.
printele trimite fiului un tabel neordonat i acela l sorteaz i trimite la printe.
Blocarea apare c printele ncepe imediat s citeasc dei fiul nici nu a nceput
sortarea.
Soluiile mele:
1) fiul trimite o variabil de stare care este poziionat pe GATA abia dup ce fiul
i-a ndeplinit sarcina
2) folossc un alt pipe special pentru a indica disponibilitatea fiului.
3) se trimite un semnal

Lucrarea nr. 5 Canale de comunicatii cu nume,


FIFO
Cnd se scrie n FIFO se iese din apel doar cnd cellalt a citit.
Pot fi folosite ntre procese ce nu sunt printe-descendent, caz n care se folosesc ca
pipe.

Funcia principal este ns de implementare a mesajelor


mesaje.h arat sctructura mesajului
send i receive le prelucreaz cu un protocol FIFO
Mesajele sunt trimise la o coad de mesaje i sunt recepionate de la o coad de
mesaje.

Lucrarea nr. 6 Modalitati IPC (comunicare interproces) in UNIX. Introducere


Mesaje, semafoare, yone de memorie partajate.
Unele versiuni pot s nu aib IPC
Dou procese independente nupot folosi aceeai cheie.
Mesajele pot fi extrase de mai muli, dar dac unul a citit, mesajul nu ajunge la
ceilali.
Se pot citi n orice ordine, nu obl FIFO.
Deci un proces cunoate chheia de acces, el poate intercepta mesajele.
Protecie slab contra hacker-ilor.
Aplicaie client-server

Lucrarea 7 Modalitati IPC. Semafoare


Ei lucreaz cu o generalizare a alg lui Dijakstra, cu vectori de semafoare.

Lucrarea 8 Modalitati IPC. Memorie partajata


Rezerv zon, o aloc procesului, dezaloc, o eliberez.

Lucrarea nr. 9 Programarea aplicatiilor TCP/IP in


UNIX
Este un protocol n care mesajul este tiat i reasamblat n datagrame, buci.
Ierarhia:
1) nivele nalte
2) TCP
3) Internet IP
4) reea
Are interfee cu utilizatorul i IP
Porturile = adrese care permit mai multor procese s foloseasc TCP
Socket de comunicaie = IP reea i de host + port
Un socket poate fi folosit simultan n mai multe conexiuni.
Fereastr de conexiune = receptorul controleaz / filtreaz numerele pachetelor
dorite.
Conexiune = socket + mrimea ferestrei + numeere de secvena.

S-ar putea să vă placă și