linux - stud.netgroup.uniroma2.itstud.netgroup.uniroma2.it/~fond_inf/slides/linux.pdf · gnu •...
TRANSCRIPT
![Page 2: LINUX - stud.netgroup.uniroma2.itstud.netgroup.uniroma2.it/~fond_inf/slides/linux.pdf · GNU • Acronimo ricorsivo “GNU’s not Unix” • Progetto lanciato da da Richard Stallman](https://reader034.vdocuments.pub/reader034/viewer/2022042318/5f07d57d7e708231d41efbde/html5/thumbnails/2.jpg)
IL SISTEMA OPERATIVO • Strato software che opera sopra l’hardware e gestisce
l’elaboratore • Windows, Linux, MacOs X, Symbian, etc.
• Funzioni • Astrazione e gestione delle risorse hardware
• Processore, Memoria, Dischi, etc, • Multitasking • Interfacce standard • Sicurezza • Prestazioni
• I programmi vedono l’elaboratore solo tramite il Sistema Operativo
![Page 3: LINUX - stud.netgroup.uniroma2.itstud.netgroup.uniroma2.it/~fond_inf/slides/linux.pdf · GNU • Acronimo ricorsivo “GNU’s not Unix” • Progetto lanciato da da Richard Stallman](https://reader034.vdocuments.pub/reader034/viewer/2022042318/5f07d57d7e708231d41efbde/html5/thumbnails/3.jpg)
LINUX • Kernel (nucleo del
sistema operativo) scritto nel 1991 da Linus Torvalds • studente di 21 anni
dell’università di Helsinki • attulmente 6 milioni di
righe di codice C • Usato in supercomputer • Dispositivi embedded
![Page 4: LINUX - stud.netgroup.uniroma2.itstud.netgroup.uniroma2.it/~fond_inf/slides/linux.pdf · GNU • Acronimo ricorsivo “GNU’s not Unix” • Progetto lanciato da da Richard Stallman](https://reader034.vdocuments.pub/reader034/viewer/2022042318/5f07d57d7e708231d41efbde/html5/thumbnails/4.jpg)
VERSIONI
![Page 5: LINUX - stud.netgroup.uniroma2.itstud.netgroup.uniroma2.it/~fond_inf/slides/linux.pdf · GNU • Acronimo ricorsivo “GNU’s not Unix” • Progetto lanciato da da Richard Stallman](https://reader034.vdocuments.pub/reader034/viewer/2022042318/5f07d57d7e708231d41efbde/html5/thumbnails/5.jpg)
GNU • Acronimo ricorsivo “GNU’s not Unix” • Progetto lanciato da da Richard
Stallman nel 1984 • per la creazione di un sistema operativo
“libero” • Il kernel “GNU Hurd” aveva problemi…
• Sistema operativo GNU/Linux • spesso chiamato “Linux” • Adotta come kernel “Linux”
• Software GNU (e Linux) rilasciati con licenza GNU Public Licence (GPL) • Software libero • Licenza “virale” • more info @
http://www.gnu.org/copyleft/gpl.html
![Page 6: LINUX - stud.netgroup.uniroma2.itstud.netgroup.uniroma2.it/~fond_inf/slides/linux.pdf · GNU • Acronimo ricorsivo “GNU’s not Unix” • Progetto lanciato da da Richard Stallman](https://reader034.vdocuments.pub/reader034/viewer/2022042318/5f07d57d7e708231d41efbde/html5/thumbnails/6.jpg)
IL SISTEMA OPERATIVO GNU/LINUX
Scheduler
Device Drivers
OS Kernel
Memory Management
Human Interface
Filesystem
Compiler Editor
Debugger
Build Automator
Networking
GPL
![Page 7: LINUX - stud.netgroup.uniroma2.itstud.netgroup.uniroma2.it/~fond_inf/slides/linux.pdf · GNU • Acronimo ricorsivo “GNU’s not Unix” • Progetto lanciato da da Richard Stallman](https://reader034.vdocuments.pub/reader034/viewer/2022042318/5f07d57d7e708231d41efbde/html5/thumbnails/7.jpg)
Scheduler
Device Drivers
OS Kernel
Memory Management
Human Interface
Filesystem
Compiler Editor
Debugger
Build Automator
Networking
GPL
GUI Web Server Utilities Package Manager
etc...
UNA DISTRIBUZIONE LINUX
![Page 8: LINUX - stud.netgroup.uniroma2.itstud.netgroup.uniroma2.it/~fond_inf/slides/linux.pdf · GNU • Acronimo ricorsivo “GNU’s not Unix” • Progetto lanciato da da Richard Stallman](https://reader034.vdocuments.pub/reader034/viewer/2022042318/5f07d57d7e708231d41efbde/html5/thumbnails/8.jpg)
LINUX IS EVERYWHERE
• Costo stimato ri-sviluppo da 0 (stime): • Nel 2004 (v. 2.6.0): ~467M€ • Nel 2006 (v. 2.6.8): ~882M€ • Nel 2011 (v. 3.0.0): ~2200M€
src: http://en.wikipedia.org/wiki/Linux_kernel#Estimated_cost_to_redevelop
embedded (ad es. routers)
smartphone/ tablet
Servers/mainframes
![Page 9: LINUX - stud.netgroup.uniroma2.itstud.netgroup.uniroma2.it/~fond_inf/slides/linux.pdf · GNU • Acronimo ricorsivo “GNU’s not Unix” • Progetto lanciato da da Richard Stallman](https://reader034.vdocuments.pub/reader034/viewer/2022042318/5f07d57d7e708231d41efbde/html5/thumbnails/9.jpg)
src: http://en.wikipedia.org/wiki/Usage_share_of_operating_systems
![Page 10: LINUX - stud.netgroup.uniroma2.itstud.netgroup.uniroma2.it/~fond_inf/slides/linux.pdf · GNU • Acronimo ricorsivo “GNU’s not Unix” • Progetto lanciato da da Richard Stallman](https://reader034.vdocuments.pub/reader034/viewer/2022042318/5f07d57d7e708231d41efbde/html5/thumbnails/10.jpg)
Supercomputer market share
![Page 11: LINUX - stud.netgroup.uniroma2.itstud.netgroup.uniroma2.it/~fond_inf/slides/linux.pdf · GNU • Acronimo ricorsivo “GNU’s not Unix” • Progetto lanciato da da Richard Stallman](https://reader034.vdocuments.pub/reader034/viewer/2022042318/5f07d57d7e708231d41efbde/html5/thumbnails/11.jpg)
![Page 12: LINUX - stud.netgroup.uniroma2.itstud.netgroup.uniroma2.it/~fond_inf/slides/linux.pdf · GNU • Acronimo ricorsivo “GNU’s not Unix” • Progetto lanciato da da Richard Stallman](https://reader034.vdocuments.pub/reader034/viewer/2022042318/5f07d57d7e708231d41efbde/html5/thumbnails/12.jpg)
![Page 13: LINUX - stud.netgroup.uniroma2.itstud.netgroup.uniroma2.it/~fond_inf/slides/linux.pdf · GNU • Acronimo ricorsivo “GNU’s not Unix” • Progetto lanciato da da Richard Stallman](https://reader034.vdocuments.pub/reader034/viewer/2022042318/5f07d57d7e708231d41efbde/html5/thumbnails/13.jpg)
![Page 14: LINUX - stud.netgroup.uniroma2.itstud.netgroup.uniroma2.it/~fond_inf/slides/linux.pdf · GNU • Acronimo ricorsivo “GNU’s not Unix” • Progetto lanciato da da Richard Stallman](https://reader034.vdocuments.pub/reader034/viewer/2022042318/5f07d57d7e708231d41efbde/html5/thumbnails/14.jpg)
COME INSTALLARLO? • Scaricare linux
• Distribuzione consigliata: xubuntu • Installarlo
• Partizione nativa • Un bootloader vi farà scegliere all’avvio quale sistema
operativo usare • Macchina virtuale
• VirtualBox (free software, multipiattaforma, www.virtualbox.org)
• VMWare (a pagamento, Windows/OSX) • Live CD/DVD
• Basta inserire il cd/dvd e riavviare il computer • Attenzione! ogni riavvio tutti i dati saranno persi (se non
salvati ad es. su una chiavetta esterna)
![Page 15: LINUX - stud.netgroup.uniroma2.itstud.netgroup.uniroma2.it/~fond_inf/slides/linux.pdf · GNU • Acronimo ricorsivo “GNU’s not Unix” • Progetto lanciato da da Richard Stallman](https://reader034.vdocuments.pub/reader034/viewer/2022042318/5f07d57d7e708231d41efbde/html5/thumbnails/15.jpg)
USERS Whoami?
• Ogni utente ha un ID (UID) ed appartiene ad uno o più gruppi • Ogni gruppo ha un ID (GID) • utente “root” = amministratore di sistema
Guardare /etc/passwd e /etc/groups
Comandi utili: adduser, userdel, su, sudo, whoami, who, last
![Page 16: LINUX - stud.netgroup.uniroma2.itstud.netgroup.uniroma2.it/~fond_inf/slides/linux.pdf · GNU • Acronimo ricorsivo “GNU’s not Unix” • Progetto lanciato da da Richard Stallman](https://reader034.vdocuments.pub/reader034/viewer/2022042318/5f07d57d7e708231d41efbde/html5/thumbnails/16.jpg)
COMANDI UTILI Name Action ls list cd change directory pwd print working directory cp/mv/rm copy/move/remove cat concatenate tail/head view the first/last lines of a file mkdir/rmdir create/remove a directory find/locate search for a file/directory grep search inside files ln Link touch create an empty file
MAN
![Page 17: LINUX - stud.netgroup.uniroma2.itstud.netgroup.uniroma2.it/~fond_inf/slides/linux.pdf · GNU • Acronimo ricorsivo “GNU’s not Unix” • Progetto lanciato da da Richard Stallman](https://reader034.vdocuments.pub/reader034/viewer/2022042318/5f07d57d7e708231d41efbde/html5/thumbnails/17.jpg)
PERMESSI SU FILE/DIR
prova a vederli con ls -al
chmod XXX file_name
![Page 18: LINUX - stud.netgroup.uniroma2.itstud.netgroup.uniroma2.it/~fond_inf/slides/linux.pdf · GNU • Acronimo ricorsivo “GNU’s not Unix” • Progetto lanciato da da Richard Stallman](https://reader034.vdocuments.pub/reader034/viewer/2022042318/5f07d57d7e708231d41efbde/html5/thumbnails/18.jpg)
TUTTO E’ UN FILE! STRUTTURA DELLE DIRECTORY SU LINUX
![Page 19: LINUX - stud.netgroup.uniroma2.itstud.netgroup.uniroma2.it/~fond_inf/slides/linux.pdf · GNU • Acronimo ricorsivo “GNU’s not Unix” • Progetto lanciato da da Richard Stallman](https://reader034.vdocuments.pub/reader034/viewer/2022042318/5f07d57d7e708231d41efbde/html5/thumbnails/19.jpg)
PROC FS Un sistema per vedere/editare informazioni su kernel e processi ad esempio: root@web:~# cat /proc/uptime
12901954.29 12678743.37
Esempio: dire al kernel di NON rispondere ai PING
cat /proc/sys/net/ipv4/icmp_echo_ignore_all
echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_all
![Page 20: LINUX - stud.netgroup.uniroma2.itstud.netgroup.uniroma2.it/~fond_inf/slides/linux.pdf · GNU • Acronimo ricorsivo “GNU’s not Unix” • Progetto lanciato da da Richard Stallman](https://reader034.vdocuments.pub/reader034/viewer/2022042318/5f07d57d7e708231d41efbde/html5/thumbnails/20.jpg)
DEV FS Accesso ai dispositivi fisici (sound card, ram, hard drive, serial/parallel interface …) e “presudo” device (/dev/null, /dev/zero, /dev/random) Esempio: Crea 1 Giga di random data
dd if=/dev/random of=/home/myhome/randomdata bs=1M count=1024
![Page 21: LINUX - stud.netgroup.uniroma2.itstud.netgroup.uniroma2.it/~fond_inf/slides/linux.pdf · GNU • Acronimo ricorsivo “GNU’s not Unix” • Progetto lanciato da da Richard Stallman](https://reader034.vdocuments.pub/reader034/viewer/2022042318/5f07d57d7e708231d41efbde/html5/thumbnails/21.jpg)
RUSSIAN ROULETTE
dd if=/dev/urandom of=/dev/kmem bs=1 count=1 seek=$RANDOM
![Page 22: LINUX - stud.netgroup.uniroma2.itstud.netgroup.uniroma2.it/~fond_inf/slides/linux.pdf · GNU • Acronimo ricorsivo “GNU’s not Unix” • Progetto lanciato da da Richard Stallman](https://reader034.vdocuments.pub/reader034/viewer/2022042318/5f07d57d7e708231d41efbde/html5/thumbnails/22.jpg)
IL COMANDO MOUNT mount -t type device dir (umount)
• Aggiunge al filesystem il contenuto del device in /dev/fstab informazioni su cosa montare all’avvio E’ possibile montare dei file (-o loop)
• Associa un file con un loop dev node (e.g. /dev/loop1) e … • montare il loop dev node ad un mounting point
ninux@ale:~$ mount /dev/sda1 on / type ext4 (rw) proc on /proc type proc (rw) sysfs on /sys type sysfs (rw,noexec,nosuid,nodev) fusectl on /sys/fs/fuse/connections type fusectl (rw) none on /sys/kernel/debug type debugfs (rw) none on /sys/kernel/security type securityfs (rw) udev on /dev type devtmpfs (rw,mode=0755) devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620) tmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,mode=0755) none on /run/lock type tmpfs (rw,noexec,nosuid,nodev,size=5242880) none on /run/shm type tmpfs (rw,nosuid,nodev)
![Page 23: LINUX - stud.netgroup.uniroma2.itstud.netgroup.uniroma2.it/~fond_inf/slides/linux.pdf · GNU • Acronimo ricorsivo “GNU’s not Unix” • Progetto lanciato da da Richard Stallman](https://reader034.vdocuments.pub/reader034/viewer/2022042318/5f07d57d7e708231d41efbde/html5/thumbnails/23.jpg)
INSTALLARE SOFTWARE Il problema delle dipendenze
• alcuni programmi dipendono da molte librerie Gnu Build System
• Autoconf, Automake, Libtools Su debian-like:
• apt-get install foo • apt-cache search foo • apt-get update • apt-file search filename.txt
./configure make make install
![Page 24: LINUX - stud.netgroup.uniroma2.itstud.netgroup.uniroma2.it/~fond_inf/slides/linux.pdf · GNU • Acronimo ricorsivo “GNU’s not Unix” • Progetto lanciato da da Richard Stallman](https://reader034.vdocuments.pub/reader034/viewer/2022042318/5f07d57d7e708231d41efbde/html5/thumbnails/24.jpg)
ARCHIVIARE, COMPRIMERE E DECOMPRIMERE Tar: archive file/dir in one file .tar (nessuna compressione) Spesso usato con algoritmo di compressione (ad es. gunzip, bunzip2) Archivio+ gunzip:
• tar cfvz nameofarchive.tar.gz target_dir • ( For bunzip2 substitute z with j )
Decompressione • tar xvfz nameofarchive.tar.gz
Se l’estensione del file non ci dice abbastanza, usare il comando “file”
![Page 25: LINUX - stud.netgroup.uniroma2.itstud.netgroup.uniroma2.it/~fond_inf/slides/linux.pdf · GNU • Acronimo ricorsivo “GNU’s not Unix” • Progetto lanciato da da Richard Stallman](https://reader034.vdocuments.pub/reader034/viewer/2022042318/5f07d57d7e708231d41efbde/html5/thumbnails/25.jpg)
SHELL La nostra interfaccia sul sistema operativo…
• Permette di eseguire comandi • Permette di definire “script” (definire variabili, cicli etc)
I comandi accettati che chiamano programmi eseguibili)
• percorso assoluto o relativo • spesso eseguibili contenuti in directory incluse nella variabile PATH • provare ad eseguire: “which NAME_OF_COMMAND”
Variable:
• Shell variable (locale, relativa a una particolare instanza della shell) • per avere la lista set, per settare VAR=VALUE, to ottenere il valore di una echo VAR
• Environment variable (ereditate da ogni programma che facciamo partire) • per avere la lista: env, per settare export or setenv, ottenere il valore di una printenv or
echo VAR
ninux@ale:~$ export PIPPO="pluto" ninux@ale:~$ printenv PIPPO pluto
ninux@ale:~$ PLUTO=”ciao" ninux@ale:~$ echo $PLUTO ciao
What shell am I using? echo $SHELL
![Page 26: LINUX - stud.netgroup.uniroma2.itstud.netgroup.uniroma2.it/~fond_inf/slides/linux.pdf · GNU • Acronimo ricorsivo “GNU’s not Unix” • Progetto lanciato da da Richard Stallman](https://reader034.vdocuments.pub/reader034/viewer/2022042318/5f07d57d7e708231d41efbde/html5/thumbnails/26.jpg)
STANDARD STREAMS Ad ogni file aperto è associato un numero
• Descrittore di file – FILE descriptor Ogni programma che gira, parte già con tre file aperti
• stdin: input da tastiera – FD 0 • stdout: output a video – FD 1 • stderr: output di errori a video – FD 2
Possiamo redirigere gli input/outpu usando: < , << , >>, > • echo "hello world" > myfile • Imposta lo stdout del programma echo a myfile
n>&m permette di redirigere il FD n verso il FD m • program 2>&1 myfile • Tutti gli output e gli errori del programmi rediretti a myfile
![Page 27: LINUX - stud.netgroup.uniroma2.itstud.netgroup.uniroma2.it/~fond_inf/slides/linux.pdf · GNU • Acronimo ricorsivo “GNU’s not Unix” • Progetto lanciato da da Richard Stallman](https://reader034.vdocuments.pub/reader034/viewer/2022042318/5f07d57d7e708231d41efbde/html5/thumbnails/27.jpg)
PIPELINES • Le “Pipes“ permettono a processi separati di comunicare
tra loro senza essere specificatamente progettati per lavorare insieme
• Esempio: • ls | grep x • Significato: prendi l’output del comando ls e passalo come
input al comando grep x
• Su Linux esistono tantissimi comandi “semplici” (tipo cat, cut, sed, grep, echo …) che fanno una cosa e possono essere combinati attraverso le pipe
![Page 28: LINUX - stud.netgroup.uniroma2.itstud.netgroup.uniroma2.it/~fond_inf/slides/linux.pdf · GNU • Acronimo ricorsivo “GNU’s not Unix” • Progetto lanciato da da Richard Stallman](https://reader034.vdocuments.pub/reader034/viewer/2022042318/5f07d57d7e708231d41efbde/html5/thumbnails/28.jpg)
SHELL TRICKS!
ESC + . à ripete l’ultimo parametro CTRL + A à vai al primo carattere CTRL + E à vai all’ultimo carattere
CTRL + K à cancella ogni carattere dalla posizione corrente fino alla fine della riga
Altri? man getline
![Page 29: LINUX - stud.netgroup.uniroma2.itstud.netgroup.uniroma2.it/~fond_inf/slides/linux.pdf · GNU • Acronimo ricorsivo “GNU’s not Unix” • Progetto lanciato da da Richard Stallman](https://reader034.vdocuments.pub/reader034/viewer/2022042318/5f07d57d7e708231d41efbde/html5/thumbnails/29.jpg)
PROCESSI • Ad Ogni processo è associato un numero identificativo
chiamato PID (Process ID) ps –aux à lista dei processi (ps: “process snapshot”)
• top / htop per vederli in tempo reale • il comando kill manda segnali ai processi (SIGTERM,
SIGKILL) • Un segnale è un “messaggio” • Quando un programma riceve un segnale, esegue alcune
operazioni definite dal programmatore in una routine chiamata “handler del segnale”
![Page 30: LINUX - stud.netgroup.uniroma2.itstud.netgroup.uniroma2.it/~fond_inf/slides/linux.pdf · GNU • Acronimo ricorsivo “GNU’s not Unix” • Progetto lanciato da da Richard Stallman](https://reader034.vdocuments.pub/reader034/viewer/2022042318/5f07d57d7e708231d41efbde/html5/thumbnails/30.jpg)
EDITOR
http://www.viemu.com/a-why-vi-vim.html
![Page 31: LINUX - stud.netgroup.uniroma2.itstud.netgroup.uniroma2.it/~fond_inf/slides/linux.pdf · GNU • Acronimo ricorsivo “GNU’s not Unix” • Progetto lanciato da da Richard Stallman](https://reader034.vdocuments.pub/reader034/viewer/2022042318/5f07d57d7e708231d41efbde/html5/thumbnails/31.jpg)
VIM MODES
Normal Visual Select
Insert Cmdline Ex
+6 additional modes! http://vimdoc.sourceforge.net/htmldoc/usr_toc.html vimtutor
![Page 32: LINUX - stud.netgroup.uniroma2.itstud.netgroup.uniroma2.it/~fond_inf/slides/linux.pdf · GNU • Acronimo ricorsivo “GNU’s not Unix” • Progetto lanciato da da Richard Stallman](https://reader034.vdocuments.pub/reader034/viewer/2022042318/5f07d57d7e708231d41efbde/html5/thumbnails/32.jpg)
VIM: BASIC COMMANDS <Esc> Enter command mode
i Enter insert mode
:w Save File
:q! Exit vim without saving
x Delete the character under the cursor
dw Delete the current word
dd Delete the current line
d$ Delete everything Right of the cursor
yy Yank the current line onto the clipboard
p Paste the clipboard
u Undo
:redo Redo
G Jump to bottom of file
/text Search for the textfrom the cursor
> Indent
set number syntax on Visual mode: markers substitute all: :%s/AAAA/BBBB/g
![Page 33: LINUX - stud.netgroup.uniroma2.itstud.netgroup.uniroma2.it/~fond_inf/slides/linux.pdf · GNU • Acronimo ricorsivo “GNU’s not Unix” • Progetto lanciato da da Richard Stallman](https://reader034.vdocuments.pub/reader034/viewer/2022042318/5f07d57d7e708231d41efbde/html5/thumbnails/33.jpg)
![Page 34: LINUX - stud.netgroup.uniroma2.itstud.netgroup.uniroma2.it/~fond_inf/slides/linux.pdf · GNU • Acronimo ricorsivo “GNU’s not Unix” • Progetto lanciato da da Richard Stallman](https://reader034.vdocuments.pub/reader034/viewer/2022042318/5f07d57d7e708231d41efbde/html5/thumbnails/34.jpg)
EXERCISE Usando vim, scrivere questo file: #!/bin/bash
echo “Hello World“
more on bash scripting: http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html
Quindi renderlo eseguibile e lanciare lo script
![Page 35: LINUX - stud.netgroup.uniroma2.itstud.netgroup.uniroma2.it/~fond_inf/slides/linux.pdf · GNU • Acronimo ricorsivo “GNU’s not Unix” • Progetto lanciato da da Richard Stallman](https://reader034.vdocuments.pub/reader034/viewer/2022042318/5f07d57d7e708231d41efbde/html5/thumbnails/35.jpg)
BASH SCRIPTING Variabili:
• modify the previous script in this way:
#!/bin/bash STR="Hello World!” echo $STR
![Page 36: LINUX - stud.netgroup.uniroma2.itstud.netgroup.uniroma2.it/~fond_inf/slides/linux.pdf · GNU • Acronimo ricorsivo “GNU’s not Unix” • Progetto lanciato da da Richard Stallman](https://reader034.vdocuments.pub/reader034/viewer/2022042318/5f07d57d7e708231d41efbde/html5/thumbnails/36.jpg)
BASH SCRIPTING If and arguments
#!/bin/bash if [ $1!=“pippo” ]; then echo “usage: $0 pippo” exit fi echo You Win!
![Page 37: LINUX - stud.netgroup.uniroma2.itstud.netgroup.uniroma2.it/~fond_inf/slides/linux.pdf · GNU • Acronimo ricorsivo “GNU’s not Unix” • Progetto lanciato da da Richard Stallman](https://reader034.vdocuments.pub/reader034/viewer/2022042318/5f07d57d7e708231d41efbde/html5/thumbnails/37.jpg)
BASH SCRIPTING loop (for, while, until) and commands:
• modify the previous script in this way:
#!/bin/bash -x for i in $( ls ); do echo “item: $i” done