115 lines
2.4 KiB
Markdown
115 lines
2.4 KiB
Markdown
# Astuces SHell
|
|
|
|
## Shell -> HTML
|
|
|
|
~~~
|
|
# apt install aha
|
|
$ script-foo-colors | aha > output.html
|
|
~~~
|
|
|
|
## Initialisation du shell
|
|
|
|
Entre les 3 modes ("login", "interactive non-login" et "non-interactive non-login") il y a de quoi se perdre à propos des fichiers chargés. Voici un rappel assez complet : <https://github.com/rbenv/rbenv/wiki/Unix-shell-initialization>
|
|
|
|
## Script shell
|
|
|
|
Style guide : <https://google.github.io/styleguide/shell.xml>
|
|
|
|
## History Bash
|
|
|
|
`bashrc` :
|
|
|
|
~~~
|
|
export HISTCONTROL=$HISTCONTROL${HISTCONTROL+,}ignoreboth
|
|
export HISTSIZE=65535
|
|
export HISTTIMEFORMAT="%c : "
|
|
~~~
|
|
|
|
> *Note* : si besoin on peut `chattr +a /root/.bash_history` pour empêcher sa suppression
|
|
|
|
## Changer l'editeur de texte par défaut pour une commande
|
|
|
|
Normalement le script (vipw, vigr, -ldapvi, ...) se réfère aux fichiers scripts (qui ne sont que des liens vers les binaires) :
|
|
|
|
~~~{.bash}
|
|
/etc/alternatives/
|
|
~~~
|
|
|
|
Sinon en ligne de commande :
|
|
|
|
~~~{.bash}
|
|
$ EDITOR=nano vipw
|
|
~~~
|
|
|
|
## Savoir si lignes en doublon dans un fichier
|
|
|
|
~~~{.bash}
|
|
$ diff <fichier> <(cat <fichier> | uniq)
|
|
~~~
|
|
|
|
## Comparer deux fichiers quant à l'existence de nouvelles lignes
|
|
|
|
~~~{.bash}
|
|
$ grep -F -x -v -f <fichier1> <fichier2>
|
|
~~~
|
|
|
|
## Tâches de fond
|
|
|
|
~~~{.bash}
|
|
$ bg = "mettre en arrière plan"
|
|
$ fg = "mettre en premier plan"
|
|
$ jobs = "lister les tâches de fond"
|
|
%% = "dernier job utilisé (représenté par un +)"
|
|
%x = "job numéro x"
|
|
~~~
|
|
|
|
~~~{.bash}
|
|
$ vi foo
|
|
^Z
|
|
[1]+ Stopped vi foo
|
|
$ tail -f bar
|
|
...
|
|
^C
|
|
$ fg
|
|
^Z
|
|
[1]+ Stopped vi foo
|
|
$ kill -9 %%
|
|
|
|
[1]+ Killed vi foo
|
|
$ ( sleep 1m; echo "Premier !" ) &
|
|
[1] 13649
|
|
$ ( sleep 30; echo "Deuxième !" ) &
|
|
[2] 13651
|
|
$ jobs
|
|
[1]- Running sleep 1m && echo ...
|
|
[2]+ Running sleep 30 && echo ...
|
|
$ fg %2
|
|
^Z
|
|
[2]+ Stopped sleep 30 && echo ...
|
|
$ jobs
|
|
[1]- Running sleep 1m && echo ...
|
|
[2]+ Stopped sleep 30 && echo ...
|
|
$ sleep 30; bg
|
|
Premier !
|
|
[2]- Done sleep 30 && echo ...
|
|
Deuxième !
|
|
$ jobs
|
|
[1]- Done sleep 1m && echo ...
|
|
$ vi foo
|
|
^Z
|
|
[1]+ Stopped vi foo
|
|
$ exit
|
|
There are stopped jobs.
|
|
$ kill -9 %% #fg :x
|
|
$ exit
|
|
~~~
|
|
|
|
## Analyse disque
|
|
|
|
Quand il s'agit de / - penser à exclure les autres partitions
|
|
|
|
~~~
|
|
# ncdu / --exclude=/home --exclude=/srv --exclude=/var ...
|
|
~~~
|
|
|
|
Sinon voir du côté de [HowtoDUC](/HowtoDUC). |