Les bases du shell (TP) Flashcards

(59 cards)

1
Q

Dans un terminal, créez et placez vous dans le répertoire ~/OSSE11/tp1.

A

sh$ mkdir -pv ~/OSSE11/tp1
sh$ cd ~/OSSE11/tp1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Affichez le répertoire courant (Working Directory).

A

sh$ pwd

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Retournez dans votre répertoire personnel (HOME)

A

sh$ cd

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Sachant que vous étiz dans ~/OSSE11/tp1 puis que vous étes aller dans ~, retournez dans le répertoire ~/OSSE11/tp1.

A

sh$ cd -

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Ouvrez un nouveau terminal en tâche de fond.

A

sh$ xterm &

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Sans changer de répertoire courant, copiez le fichier /pub/FISE_OSSE11/shell/fich.dat dans le
répertoire /tmp sous le nom f1.

A

sh$ cp -v /pub/FISE_OSSE11/shell/fich.dat /tmp/f1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Quelle est la taille en octet de /tmp/f1 ?

A

sh$ cat /tmp/f1
sh$ ls -l /tmp/f1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Sans changer de répertoire courant, déplacez le fichier /tmp/f1 dans /tmp/d1/d2/f1-de-d2. Il faudra
d’abord créer le répertoire /tmp/d1/d2.

A

sh$ mkdir -pv /tmp/d1/d2
sh$ mv -v /tmp/f1 /tmp/d1/d2/f1-de-d2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Sans changer de répertoire courant, copiez l’arborescence /tmp/d1/d2 dans votre HOME sous le nom
OSSE11/tp1/exo2.

A

sh$ mkdir -pv OSSE11/tp1
sh$ cp -rv /tmp/d1/d2 OSSE11/tp1/exo2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Vérifiez, en une seule commande, que les deux fichiers OSSE11/tp1/exo2/f1-de-d2 et
OSSE11/tp1/exo2/d1/d2/f1-de-d2 sont bien de même taille.

A

sh$ ls -l OSSE11/tp1/exo2/f1-de-d2 OSSE11/tp1/exo2/d1/d2/f1-de-d2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Créez le fichier a qui contient une seule lettre ‘A’.

A

sh$ echo -n ‘A’ > fichier_a

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Créez un nouveau fichier a qui contient 10 fois le contenu actuel du fichier_a (on utilisera un fichier
intermédiaire /tmp/1).

A

sh$ cat a a a a a a a a a a > /tmp/1
sh$ mv -v /tmp/1 a

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Lancez un atril en avant-plan (foreground).

A

sh$ atril /pub/FISE_OSSE11/Supports/sys-poly.pdf

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Lancez un atril en arrière-plan (background).

A

sh$ atril /pub/FISE_OSSE11/Supports/sys-poly.pdf &

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Ramenez le processus en avant-plan (foreground) grâce à la commande builtin fg, qui ramène en avant-
plan le dernier processus lancé en arrière-plan.

A

sh$ fg

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Ouvrez un second terminal dont le HOME est ce répertoire ~/OSSE/term2.

A

sh$ HOME=~/OSSE11/term2 xterm &

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Ajoutez le répertoire ~/OSSE11/bin à votre PATH.

A

sh$ export PATH=”$PATH:~/OSSE11/bin”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Donnez la taille en octet de /pub/FISE_OSSE11/shell/gen-projet.sh.

A

sh$ wc -c /pub/FISE_OSSE11/shell/gen-projet.sh

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Donnez uniquement la taille en octet du fichier /pub/FISE_OSSE11/shell/gen-projet.sh.

A

sh$ wc -c < /pub/FISE_OSSE11/shell/gen-projet.sh

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Donnez la taille en octet de /pub/FISE_OSSE11/shell/gen-projet.sh sans utiliser la fonction wc.

A

sh$ sz=$(stat -c ‘%s’ /pub/FISE_OSSE11/shell/gen-projet.sh) # version linux
sh$ echo “sz = $sz”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Triez le fichier /pub/FISE_OSSE11/shell/unsort.dat à l’aide de la commande sort et stockez le
résultat dans le fichier /tmp/1.

A

sh$ sort /pub/FISE_OSSE11/shell/unsort.dat > /tmp/1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Générez /tmp/2 à partir /tmp/1 en enlevant les lignes semblables grâce à la commande uniq.

A

sh$ uniq /tmp/1 /tmp/2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Affichez le contenu du fichier /pub/FISE_OSSE11/shell/expr-arith.dat

A

sh$ cat /pub/FISE_OSSE11/shell/expr-arith.dat
ou
sh$ less /pub/FISE_OSSE11/shell/expr-arith.dat # q pour quitter

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Créez le fichier /tmp/expr2 contenant l’expression de /pub/FISE_OSSE11/shell/expr-arith.dat
multipliée 3 fois par elle même en utilisant la commande echo et une variable.

A

sh$ x=”($(cat /pub/FISE_OSSE11/shell/expr-arith.dat))”
sh$ echo “$x * $x * $x” > /tmp/expr2

25
Supprimez les fichiers exprN du répertoire /tmp.
sh$ rm -v /tmp/expr*
26
Affichez la 3e colonne du fichier /pub/FISE_OSSE11/shell/select.dat.
sh$ cut -f 3 /pub/FISE_OSSE11/shell/select.dat
27
Affichez la première et la troisième colonne de /pub/FISE_OSSE11/shell/select.dat.
sh$ cut -f 1,3 /pub/FISE_OSSE11/shell/select.dat
28
Affichez les deux premières lignes de /pub/FISE_OSSE11/shell/select.dat.
sh$ head -n 2 /pub/FISE_OSSE11/shell/select.dat
29
Affichez les trois dernières lignes de /pub/FISE_OSSE11/shell/select.dat.
sh$ tail -n 3 /pub/FISE_OSSE11/shell/select.dat
30
Affichez les lignes du fichier /pub/FISE_OSSE11/shell/select.dat contenant le mot Alice.
sh$ grep -e 'Alice' /pub/FISE_OSSE11/shell/select.dat
31
Avec la commande sed affichez les trois premières lignes de /pub/FISE_OSSE11/shell/select.dat.
sh$ sed -e '4,$d' /pub/FISE_OSSE11/shell/select.dat
32
Avec la fonction sed affichez le fichier /pub/FISE_OSSE11/shell/select.dat privé de ses trois premières lignes.
sh$ sed -e '1,3d' /pub/FISE_OSSE11/shell/select.dat
33
Affichez /pub/FISE_OSSE11/shell/select.dat privé de ses deux dernières lignes. Pour cela, il faut au préalable calculer le nombre de lignes du fichier.
sh$ nb=$(wc -l
34
Affichez les lignes de /pub/FISE_OSSE11/shell/select.dat ne contenant pas le mot Alice.
sh$ sed -e '/Alice/d' /pub/FISE_OSSE11/shell/select.dat
35
Affichez les lignes de /pub/FISE_OSSE11/shell/select.dat contenant le mot Alice.
sh$ sed -e '/Alice/!d' /pub/FISE_OSSE11/shell/select.dat
36
Affichez le contenu du fichier /pub/FISE_OSSE11/shell/select.dat, mais en remplaçant Alice par Anne
sh$ sed -e 's/Alice/Anne/g' /pub/FISE_OSSE11/shell/select.dat
37
Affichez le contenu du fichier /pub/FISE_OSSE11/shell/select.dat, mais en remplaçant la date du 01/08/2001 par 03/08/2001.
sh$ sed -e 's,01/08/2001,03/08/2001,' /pub/FISE_OSSE11/shell/select.dat
38
Affichez la première colonne de /pub/FISE_OSSE11/shell/select.dat.
sh$ sed -e 's/\t.*//' /pub/FISE_OSSE11/shell/select.dat
39
Avec la fonction sed affichez la troisième colonne de /pub/FISE_OSSE11/shell/select.dat.
sh$ sed -e 's/[^\t]*\t[^\t]*\t\([^\t]*\)/\1/' /pub/FISE_OSSE11/shell/select.dat
40
Avec la fonction sed affichez la première et la troisième colonne du fichier /pub/FISE_OSSE11/shell/select.dat.
sh$ sed -e 's/\([^\t]*\)\t[^\t]*\t\([^\t]*\)/\1\t\2/' /pub/FISE_OSSE11/shell/select.dat
41
Échangez la première et la troisième colonne du fichier /pub/FISE_OSSE11/shell/select.dat.
sh$ sed -e 's/\([^\t]*\)\t[^\t]*\t\([^\t]*\)/\2\t\1/' /pub/FISE_OSSE11/shell/select.dat
42
Donnez la première ligne du fichier /pub/FISE_OSSE11/shell/select.dat qui contient le mot Alice en utilisant grep et head.
sh$ grep "Alice" /pub/FISE_OSSE11/shell/select.dat | head -n 1
43
Donnez la première ligne du fichier /pub/FISE_OSSE11/shell/select.dat qui contient le mot Alice en utilisant sed et éventuellement head.
sh$ sed -n '/Alice/{p; q;}' /pub/FISE_OSSE11/shell/select.dat
44
Donnez la destination de la première ligne qui contient Alice du fichier /pub/FISE_OSSE11/shell/select.dat en utilisant grep, head et cut.
sh$ grep "Alice" /pub/FISE_OSSE11/shell/select.dat | head -n 1 | cut -d' ' -fNF
45
Donnez la destination de la première ligne qui contient Alice du fichier /pub/FISE_OSSE11/shell/select.dat en utilisant sed et cut.
sh$ sed -n '/Alice/{p; q;}' /pub/FISE_OSSE11/shell/select.dat | cut -d' ' -fNF
46
Donnez la destination de la dernière ligne qui contient Alice du fichier /pub/FISE_OSSE11/shell/select.dat.
sh$ grep "Alice" /pub/FISE_OSSE11/shell/select.dat | tail -n 1 | cut -d' ' -fNF
47
Affichez tout ce qui est contenu dans votre répertoire HOME.
sh$ ( cd ; find . -print )
48
Affichez tous les fichiers (réguliers) du répertoire courant.
sh$ find . -type f -print
49
Affichez tous les répertoires du répertoire courant.
sh$ find . -type d -print
50
Affichez tous les fichiers (réguliers) du répertoire courant dont la taille est supérieure à 10ko.
sh$ find . -type f -size +10k -print
51
Recherchez, parmi les fichiers .c du répertoire /pub/FISE_OSSE11/shell/projet, ceux qui contiennent un appel à la fonction strcmp
sh$ find /pub/FISE_OSSE11/shell/projet -type f -name '*.c' -exec grep -w -l -e strcmp {} \;
52
Créez une archive du répertoire /pub/FISE_OSSE11/shell/projet dans /tmp/projet.tar.
sh$ ( cd $(dirname /pub/FISE_OSSE11/shell/projet) ; tar -cvf /tmp/projet.tar projet ) ou sh$ tar -C $(dirname /pub/FISE_OSSE11/shell/projet) -cvf /tmp/projet.tar projet
53
isualisez les noms des fichiers de l’archive /tmp/projet.tar.
sh$ tar -tvf /tmp/projet.tar
54
Restaurez l’archive /tmp/projet.tar dans /tmp
sh$ tar -C /tmp -xf /tmp/projet.tar
55
Grâce à tar et find, créez l’archive /tmp/code.tar contenant uniquement les fichiers .c et .h de l’arborescence /pub/FISE_OSSE11/shell/projet.
sh$ find /pub/FISE_OSSE11/shell/projet -name "*.c" -o -name "*.h" | tar -cvf /tmp/code.tar -T -
56
Déterminez à l’aide de la commande tty le nom du fichier spécial associé à votre terminal.
sh$ tty
57
Lancez un nouveau terminal nommé A.
sh$ xterm -name A &
58
Dans le terminal A, changez le comportement de sorte que le « retour-arrière » soit maintenant produit par la touche m, et que le signal de fin de fichier soit produit par la touche f.
sh$ stty erase m # dans le terminal A sh$ stty eof f # dans le terminal A
59
Lancez une commande echo sur le terminal B qui écrit "hello world" sur le terminal A.
sh$ echo 'hello world' > /dev/pts/N-A