« Bash » : différence entre les versions
Aucun résumé des modifications |
|||
| (4 versions intermédiaires par le même utilisateur non affichées) | |||
| Ligne 11 : | Ligne 11 : | ||
"\e[6~": history-search-forward | "\e[6~": history-search-forward | ||
== reptyr == | |||
retrieve a pid | |||
récupérer le pid dans un autre shell | |||
== hard reboot, magic commandes, /proc/ == | |||
!!! C'est comme appuyer sur RESET !!! | |||
echo 1 > /proc/sys/kernel/sysrq | |||
echo b > /proc/sysrq-trigger | |||
== les commandes de test == | == les commandes de test == | ||
| Ligne 112 : | Ligne 123 : | ||
== tr == | == tr == | ||
$ echo 'hi' | tr '[:lower:]' '[:upper:]' | |||
HI | HI | ||
| Ligne 118 : | Ligne 129 : | ||
find /PATH/to/FILE/ -name [0-4]-[0-4] -exec ls -l {} \; | find /PATH/to/FILE/ -name [0-4]-[0-4] -exec ls -l {} \; | ||
trouver les fichiers modifié dans un interval de temps : | |||
find . -mmin $((($(date --date='2019-04-16 11:00:00' +%s) - $(date --date='now' +%s)) /60)) | |||
== decouper une string variable en array == | == decouper une string variable en array == | ||
| Ligne 141 : | Ligne 156 : | ||
total 1116 | total 1116 | ||
That is the total number of file system blocks, including indirect blocks, used by the listed files. | That is the total number of file system blocks, including indirect blocks, used by the listed files. | ||
== exit == | |||
exit 0 == OK | |||
exit 1 == false | |||
true # The "true" builtin. | |||
echo "exit status of \"true\" = $?" # 0 | |||
! true | |||
echo "exit status of \"! true\" = $?" # 1 | |||
Dernière version du 6 août 2020 à 15:15
PageUp and PageDown history search auto completion on the BASH shell[modifier]
http://www.electrictoolbox.com/pageup-history-auto-completion-bash-shell/
/etc/inputrc
The PageUp and PageDown keys are set with the "\e[5~": & "\e[6~": lines, so you'd need to comment them out and add new commands as follows:
#"\e[5~": beginning-of-history #"\e[6~": end-of-history "\e[5~": history-search-backward "\e[6~": history-search-forward
reptyr[modifier]
retrieve a pid
récupérer le pid dans un autre shell
hard reboot, magic commandes, /proc/[modifier]
!!! C'est comme appuyer sur RESET !!!
echo 1 > /proc/sys/kernel/sysrq echo b > /proc/sysrq-trigger
les commandes de test[modifier]
Tester un fichier (de type répertoire) dans l'exemple suivant =>
if [ -d /home/talevas ]; then echo test; fi
if test -d /home/talevas ; then echo ok; else echo plouf; fi if [ -d /home/talevas ]; then echo ok; else echo plouf; fi
Tester une chaine de caractère =>
Ici on test un user existe dans /etc/pasword.
grep ${USER} /etc/passwd
cette commande va nous retourne un STRING ou pas selon que le suer existe ou non
TEST=grep ${USER} /etc/passwd
if test -n "$TEST" ; then echo ok; else echo plouf; fi
if [ -n "$TEST" ] ; then echo ok; else echo plouf; fi
Retourne OK si le user existe ou PLOUFF s'il n'existe pas
TEST=grep ${USER} /etc/passwd
if test -z "$TEST" ; then echo ok; else echo plouf; fi
if [ -z "$TEST" ] ; then echo ok; else echo plouf; fi
Retourne OK si le user n'existe pas ou PLOUFF s'il existe
`ARG1 -eq ARG2' `ARG1 -ne ARG2' `ARG1 -lt ARG2' `ARG1 -le ARG2' `ARG1 -gt ARG2' `ARG1 -ge ARG2'
These arithmetic binary operators return true if ARG1 is equal, not-equal, less-than, less-than-or-equal, greater-than, or greater-than-or-equal than ARG2, respectively.
tiré du manuel =>
`-z STRING'
True if the length of STRING is zero.
`-n STRING'
`STRING'
True if the length of STRING is nonzero.
SED / sed[modifier]
sed -i s/avant/après/g file.txt -i[SUFFIX], --in-place[=SUFFIX]
edit files in place (makes backup if extension supplied)
sed -i 3{s/\[\[:alnum:\]\]/t/g} test.fr.vhost
3 => 3eme ligne
{ ce qu'on y applique }
sed -i 3{s/[[:alnum:]]*^/$date/g} test.fr.vhost
[[:alnum:]]*^ => tout les alphanumériques et n'importe quoi ensuite.
EXPR[modifier]
expr substr $VALUE 9 2 expr length $VALUE if [ `expr length $VALUE` -lt "2" ]
Addition while[modifier]
while [ $i -le 250 ]; do echo toto; i=$[i+1]; done;
Jouer avec les variables[modifier]
http://linuxgazette.net/issue57/eyler.html
variables var decoupage[modifier]
cat ${PATHFROM}/frontaux.access.${DATE}.log | while read ligne ; do echo ${ligne#*|} >> ${PATHTO}/${ligne%|*}.file; done
prendre les 3 dernier char
${PathToFile:$((${#PathToFile} - 3)):3 }
cut[modifier]
change le délimiteur par defaut <tab> pour l'espace et prends les champs de 6 à 9
cut -d' ' -f 6,7,8,9
tr[modifier]
$ echo 'hi' | tr '[:lower:]' '[:upper:]' HI
FIND[modifier]
find /PATH/to/FILE/ -name [0-4]-[0-4] -exec ls -l {} \;
trouver les fichiers modifié dans un interval de temps :
find . -mmin $((($(date --date='2019-04-16 11:00:00' +%s) - $(date --date='now' +%s)) /60))
decouper une string variable en array[modifier]
string="10.10.25.211 10.10.25.212 10.10.25.213"
myarray=($string)
echo ${myarray[0]}
10.10.25.211
echo ${myarray[1]}
10.10.25.212
....
trouver le nombre d'objets dans le array
echo ${#myarray[@]}
3
Déterminer le path du script en cours d’exécution[modifier]
`dirname \"$0\"`
ls[modifier]
# ls -s | awk '{ SUM+=$1 } END{print SUM}'
1116
# ls -l | grep total
total 1116
That is the total number of file system blocks, including indirect blocks, used by the listed files.
exit[modifier]
exit 0 == OK exit 1 == false
true # The "true" builtin. echo "exit status of \"true\" = $?" # 0 ! true echo "exit status of \"! true\" = $?" # 1