OS 3 Linux
OS 3 Linux
Disciplina:
Operating Systems
Systèmes d’exploitation
credits to / d'après
Alex Weeks
" The Linux System
Administrator's Guide "
2
Linux file system / système de fichiers
(Filesystem Hierarchy Standard 3.0)
credits to / d'après
Alex Weeks
" The Linux System
Administrator's Guide "
3
Linux file system
4
Linux file system
credits to / d'après
Machtelt Garrels
"Introduction to Linux"
5
HELP commands / commandes d’AIDE
man command
Format and display online (in the operating
command - - help
6
Practice Platform & Documentation /
Plateforme pratique et documentation
LAB
Debian documentation and manuals /
documentation Debian et manuals
www.debian.org/doc/#manuals
www.debian.org/doc/index.fr.html#manuals
Note: For details about a specific command, use the “man-pages” (embedded in the
operating system or on the internet) /
Remarque: Pour plus d'informations sur une commande spécifique, utilisez les "man-
pages" (intégrés dans le système d'exploitation ou sur Internet)
http://manpages.debian.org/cgi-bin/man.cgi
7
Linux: Command Format / La forme
d’une commande
command [arg 1]...[arg m] [-opt 1]...[-opt n]
arg argument
opt option
Examples / Exemples :
ls
ls -R
ls -l
ls -a
ls -alR
8
Linux and Windows commands /
commandes Linux et Windows
Homework for the next lab / Devoir pour le labo
suivant
9
“Quickstart” commands / commandes
10
“Filesystem Hierarchy Standard FHS”
commands / commandes
12
Commands / commandes - 2
13
Commands / commandes - 3
14
Commands / commandes - 4
15
Commands / commandes - 5
16
Commands / commandes - 6
18
Commands / commandes - 8
19
Commands / commandes - 9
alias
unalias
help
echo string display a line of text (string)
let performs arithmetic on shell variables
printf
read to read one line from standard input
readarray
20
Commands / commandes - 10
(configure the network / configurer le
réseau)
ip command
ifconfig
netstat Display network connections, routing tables, interface
statistics, masquerade, connections and multicast memberships /
Pour afficher les connexions réseau, les tables de routage, les
statistiques d'interface, le masquerade, les connexions et les
appartenances multicast
/etc/resolv.conf
/etc/nsswitch.conf 21
Commands / commandes - 11
(check the network / vérifier le
réseau)
ping
traceroute
whois
22
Homework for the next lab / Devoir
pour le labo suivant
23
Security - Files permissions /
Sécurité - autorisations des fichiers
marian:~> ls -l TestFile123
-rw-rw-r-- 1 marian users 7 Oct 18 11:39 TestFile123
r = read access
w = write permission
x = execute permission
24
Security - Files permissions /
Sécurité - autorisations des fichiers
marian:~> ls -l TestFile123
-rw-rw-r-- 1 marian users 7 Oct 18 12:39 TestFile123
26
Script
#! /bin/bash
. . . command 1
. . . command 2
. . . command 3
echo "$PATH"
/usr/local/bin:/usr/bin:/bin 29
Single Quotes / Citations simples
30
Variables definition / Définition des
variables
In bash for a variable there is no data type / Dans
bash, pour une variable il n'y a pas de type de
données.
Example / Exemple
x=1
y=2
z=$x+$y
32
Variables / Variables (cont)
#! /bin/bash
VARIAB=“some_characters_to_display”
echo $VARIAB
Homework 1: Homework 2:
#! /bin/bash #! /bin/bash
echo ls echo $(ls)
34
Arguments / Argumentes
#!/bin/bash
echo "Is $2 older than $1 ?"
echo "...this is your homework!"
36
Arguments / Argumentes
#!/bin/bash
echo "Is $2 older than $1 ?"
echo "...this is your homework!"
37
Multiples arguments / Argumentes
multiples
The "$@" variable - to pass a variable number of
arguments to a script (in this case the variable is an
array that contains all input parameters). / La
variable "$@" - pour transmettre un nombre
variable d'arguments à un script (dans ce cas, la
variable est un tableau contenant tous les
paramètres d'entrée).
#!/bin/bash
for i in "$@"
do
echo "there_is_another_brick_in_the_wall"
done 38
Arithmetic (Integer) Comparison /
Comparaison arithmétique
Arithmetic (integer) comparisons / Comparaisons
arithmétiques (entières) :
if test_expression
then statement
fi
42
IF … THEN … ELIF … ELSE
if test_expression1 ;
then statement1 ;
elif test_expression2 ;
then statement2 ;
else statement3 ;
fi
43
Very common condition examples /
Exemples pour conditions très
communes
! EXPRESSION The EXPRESSION is false
-n STRING The length of STRING is greater than zero
-z STRING The lengh of STRING is zero (it is empty)
STRING1 = STRING2 STRING1 is equal to STRING2
STRING1 != STRING2 STRING1 is not equal to STRING2
INTEGER1 -eq INTEGER2 INTEGER1 is numerically equal to INTEGER2
INTEGER1 -gt INTEGER2 INTEGER1 is numerically greater than INTEGER2
INTEGER1 -lt INTEGER2 INTEGER1 is numerically less than INTEGER2
-d FILE FILE exists and is a directory
-e FILE FILE exists
-r FILE FILE exists and the read permission is granted
-s FILE FILE exists with size greater than zero (not empty)
-w FILE FILE exists and the write permission is granted
-x FILE FILE exists and the execute permission is granted
44
SELECT
45
CASE
case expression in
case1) statement1 ;;
case2) statement2 ;;
...
casen) statementn ;;
esac
46
EXIT
47
FOR
Example / Exemple
#! /bin/bash
for VAR in 1 2 3 4 5; do
echo The value of variable VAR is:
echo $VAR
done
49
WHILE
50
UNTIL
51
FUNCTION
1 - to group some commands /
regrouper certaines commandes
Declaring a function / Déclaration d'une fonction:
function name { code_and_commands }
function my_quit {
exit
}
function my_hello {
echo Hello!!!!
}
52
FUNCTION
2 - to use the function / utiliser la
fonction
Calling a function: write function name /
Appel d'une fonction: écrire le nom de la fonction
#!/bin/bash
my_hello
my_quit
echo test_on_screen
53
FUNCTION and PARAMETERS /
FONCTION et PARAMETRES
Function with one parameter / Fonction avec un
paramètre
function fx {
echo $1
}
56
Redirection - 2
57
Redirection - 3
credits to www.wikipedia.org
58
Redirection - 4
59
Redirection - 5
60
Pipes / Tubes
61
Operators – in decreasing order of
equal-precedence - 1
62
Operators – in decreasing order of
equal-precedence - 2
64
Regular expressions (regexp) /
Expressions régulières
Regular expressions are patterns to be matched
in a search operation: very useful in
programming languages (Java, Perl), text
processing (grep, sed, vim), etc. / Les
expressions régulières sont des modèles à
rechercher dans une opération de recherche:
très utiles dans les langages de programmation
(Java, Perl) et le traitement de texte (grep, sed,
vim), etc.
65
Regular expressions (regexp) /
Expressions régulières
metacharacter = special character (or sequences of
characters) that has a special meaning and is used to
represent something else. / métacaractère =
caractère spécial (ou séquence de caractères) ayant
une signification spéciale et utilisé pour représenter
autre chose.
expl: In regular expression the metacharacter ^ means
"not". So "m" means "match m" and "^m" means
"do not match m" / Dans l'expression régulière, le
métacaractère ^ signifie "pas". Donc "m" signifie
"match m" et "^m" signifie "ne correspond pas m".
66
Regular expressions (expl.) /
Expressions régulières (expl.)
\n , \t , \r are interpreted as newline , tab ,
carriage return
70
Arithmetic evaluation / Évaluation
arithmétique
!! bash only uses integers to respond (display) !!
bash n'utilise que des entiers pour répondre (affichage)
71
String comparisons / Comparaisons de
chaînes
<
<=
>
>=
= ( or == )
!=
-z ( null )
-n ( not null )
72
Bash debugging
#!/bin/bash -x
73
Other commands / commandes
74
Other commands / commandes
(homework)
75
Scheduling / programmation des
tâches
CRON automatically runs tasks at regular
intervals (in the background) / CRON exécute
automatiquement les tâches à intervalles
réguliers (en arrière-plan)
The command is executed when the minute,
hour, and month fields match the current time;
AND at least one of the two day fields (day of
month, or day of week) match the current day. /
La commande est exécutées lorsque les champs
des minutes, des heures et des mois
correspondent à l'heure actuelle; ET au moins
l'un des champs de deux jours (jour du mois ou
jour de la semaine) correspond au jour actuel.76
Scheduling / programmation des
tâches (cont.)
Commands / Commandes
crontab -e Edit or create a crontab file / Modifier (créer) un fichier crontab
crontab –l Display crontab file / Afficher le fichier crontab
crontab –r Remove crontab file / Supprimer le fichier crontab
* * * * * command_to_be_executed
77
Scheduling / programmation des
tâches (cont.)
* * * * * command_to_be_executed
| | | | |
| | | | +----- day of week (0 – 7)
| | | +------- month (1 - 12)
| | +--------- day of month (1 - 31)
| +----------- hour (0 - 23)
+------------- min (0 - 59)
at 5.00 PM every Monday to Wednesday but only in July / à 17h00 tous les
lundi au mercredi, mais seulement en Juillet
0 17 * 7 1-3 /home/user/script1
- - - - -
| | | | |
| | | | +----- day of week (0 - 6) (Sunday=0)
| | | +------- month (1 - 12)
| | +--------- day of month (1 - 31)
| +----------- hour (0 - 23)
+------------- min (0 - 59)
79
Script scheduling / programmation
des tâches (un script)
Example 2 / Exemple 2
It means the command will run at 8:20am on the 10th and 20th of each
month; AND every Thursday. / Cela signifie que la commande se
déroulera à 8h20 le 10 et le 20 de chaque mois; ET tous les jeudis.
20 8 10,20 * 4 /home/user/script2
- - - - -
| | | | |
| | | | +----- day of week (0 - 6)
| | | +------- month (1 - 12)
| | +--------- day of month (1 - 31)
| +----------- hour (0 - 23)
+------------- min (0 - 59)
80
Annex 1: Windows MS-DOS vs. Linux
and Unix / Windows MS-DOS contre
Linux et Unix
attrib chmod
backup tar
dir ls
cls clear
copy cp
81
Annex 1: Windows MS-DOS vs. Linux
and Unix / Windows MS-DOS contre
Linux et Unix (cont.)
del rm
deltree rm -R , rmdir
82
Annex 1: Windows MS-DOS vs. Linux
and Unix / Windows MS-DOS contre
Linux et Unix (cont.)
move , rename mv
cd cd , chdir
md mkdir
win startx 83
Annex 2: Linux (and Unix) commands
/ commandes Linux (et Unix)
Not all commands work with any user (root vs. other
users) because privileges. / Toutes les commandes ne
fonctionnent pas avec tous utilisateurs (root ou autre
utilisateur), à cause des privilèges.
84
Annex 2: Linux (and Unix) commands
/ commandes Linux (et Unix) (cont.)
A: a2p | ac | addgroup | adduser | alias | agrep | apropos | apt-
cache | apt-get | aptitude | ar | arch | arp | as | aspell | at | atq |
atrm | awk
B: basename | bash | batch | bc | bdiff | bfs | bg | biff | break |
bs | bye
C: cal | calendar | cancel | cat | cc | cd | cfdisk | chdir | checkeq |
checknr | chfn | chgrp | chkey | chmod | chown | chroot | chsh |
cksum | clear | cls | cmp | col | comm | compress | continue |
copy | cp | cpio | crontab | csh | csplit | ctags | cu | curl | cut
D: date | dc | dd | delgroup | deluser | depmod | deroff | df |
dhclient | diff | dig | dir | dircmp | dirname | dmesg | dos2unix |
dpkg | dpost | du
85
Annex 2: Linux (and Unix) commands
/ commandes Linux (et Unix) (cont.)
E: echo | ed | edit | egrep | eject | elm | emacs | enable | env |
eqn | ex | exit | expand | expr
F: fc | fdisk | fg | fgrep | file | find | findsmb | finger | fmt | fold |
for | foreach | free | fromdos | fsck | ftp | fuser
G: gawk | getfacl | gpasswd | gprof | grep | groupadd | groupdel
| groupmod | gunzip | gview | gvim | gzip
H: halt | hash | hashstat | head | help | history | host | hostid |
hostname
I: id | ifconfig | ifdown | ifup | info | init | insmod | iostat | ip |
isalist | iwconfig
J: jobs | join
K: keylogin | kill | killall | ksh
86
Annex 2: Linux (and Unix) commands
/ commandes Linux (et Unix) (cont.)
L: last | ld | ldd | less | lex | link | ln | lo | locate | login |
logname | logout | losetup | lp | lpadmin | lpc | lpq | lpr | lprm |
lpstat | ls | lsof | lsmod| lzcat | lzma
M: mach | mail | mailcompat | mailx | make | man | md5sum |
merge | mesg | mii-tool | mkdir | mkfs | mkswap | modinfo |
modprobe | more | mount | move | mt | mv | myisamchk | mysql
| mysqldump
N: nc | neqn | netstat | newalias | newform | newgrp | nice |
niscat | nischmod | nischown | nischttl | nisdefaults | nisgrep |
nismatch | nispasswd | nistbladm | nl | nmap | nohup | nroff |
nslookup
O: od | on | onintr | optisa
87
Annex 2: Linux (and Unix) commands
/ commandes Linux (et Unix) (cont.)
P: pack | pagesize | parted | partprobe | passwd | paste | pax |
pcat | perl | pg | pgrep | pico | pine | ping | pkill | poweroff | pr |
printenv | priocntl | printf | ps | pstree | pvs | pwd | python
Q: quit
R: rcp | readlink | reboot | red | rehash | remsh | rename | renice
| repeat | replace | rgview | rgvim | rlogin | rm | rmail | rmdir |
rmmod | rn | route | rpcinfo | rsh | rsync | rview | rvim
S: s2p | sag | sar | scp | screen | script | sdiff | sed | sendmail |
service | set | setenv | setfacl | sfdisk | sftp | sh | sha224sum |
sha256sum | sha384sum | sha512sum | shred | shutdown |
signals | sleep | slogin | smbclient | sort | spell | split | stat | stop
| startx | strftime | strip | stty | su | sudo | swapoff | swapon |
sysklogd
88
Annex 2: Linux (and Unix) commands
/ commandes Linux (et Unix) (cont.)
T: tabs | tac | tail | talk | tar | tbl | tcopy | tcpdump | tcsh | tee |
telinit | telnet | test | time | timex | todos | top | touch | tput | tr
| traceroute | tree | troff | tty
U: ul | umask | unalias | uname | uncompress | unhash | uniq |
unlink | unlzma | unmount | unpack | untar | until | unxz | unzip |
uptime | useradd | userdel | usermod
V: vacation | vedit | vgrind | vi | view | vim | vipw | visudo |
vmstat
W: w | wait | wall | wc | wget | whereis | whatis | which | while|
who | whoami | whois | write
X: X | xargs | xfd | xhost | xinit | xlsfonts | xorg | xset | xterm |
xrdb | xz | xzcat
Y: yacc | yes | yppasswd | yum
Z: zcat | zip | zipcloak | zipinfo | zipnote | zipsplit 89
Annex 3: Linux and Unix top
commands / Commandes principales
Linux et Unix
man , help
cd , chdir
ls
cp
mv
rm
chmod
nano , vi
pwd
tar
Find
grep
ip , ifconfig
date
kill
90