This is an old revision of the document!
Table of Contents
Divers
Remplacer dan fichier (SED ; VI)
Remplacer dans fichier (vi) :
:%s/search_string/replacement_string/g
Exemple :
:%s/<\/br>/<br \/>/g
Remplacer dans fichier (sed) :
sed -i -e "s/chaines1/chaine2/g" fichier
rajouter # en début de toutes les lignes :
:%s/^/#/g
https://its.ucsc.edu/unix-timeshare/tutorials/clean-ctrl-m.html
Problème caractères ^M à la fin des lignes de fichiers venant de Windows :
vi -b <fichier>
:%s/^M//g
vi
Pour changer de coloscheme en live dans vi :
:colorscheme murphy
Pour undo : :u
Pour redo après undo : ctrl+r
Pour aller au début du fichier : :1 (ça va à la ligne 1)
Pour aller à la fin du fichier : G (maj+g)
find
find . -type f -newermt "2019-08-10 18:00:00" ! -newermt "2019-09-01 07:00:00" -exec ls -l {} \;
find . -type f ! -path "*/squash/*" -mtime -3 -exec ls -lh --time-style="+%Y-%m-%d %H:%M:%S"
find . -type f -size +500000k -mtime +3 -exec ls -lh --time-style="+%Y-%m-%d %H:%M:%S" {} \; | awk '{ print $8 " : " $5 " (" $6 " " $7 ")" }'
Rename en masse
find . -type f -iname "*.repo" -exec mv {} "{}.old" \;
grep récursif
find . -type f -print | xargs grep CCM
Trouver le dossier qui contient beaucoup de fichiers (inodes)
find / -xdev -printf '%h\n' | sort | uniq -c | sort -k 1 -n
ls -lSR / | sort -k 5 -n
find / -type f -printf '%s\t%p\n' | sort -n | cut -f2-
Tester connexion SSH
$ ssh -q user@downhost exit $ echo $? 255 $ ssh -q user@uphost exit $ echo $? 0
Remonter en RW un volume en lecture seule
[read only | readonly | read-only] Lister les filesystem en lecture seule / read-only : grep "\sro[\s,]" /proc/mounts mount -o remount,rw /
SSH/SCP à distance
scp -r -o ConnectTimeout=10 -o StrictHostKeyChecking=no /tmp/ root@1.0.40.2:/tmp/
ssh -o StrictHostKeyChecking=no -n root@1.0.33.20 'ls -lsa /tmp/backup'
Screen
* créer screen avec nom : screen -S <nom> * quitter : Ctrl+A puis D * voir les screen qui tournent : screen -ls * récupérer screen avec nom : screen -r <nom> * récupérer screen avec numéro : screen -r <numero> * quitter complètement : exit <ou> screen -X -S <nom> kill * Pour créer un screen, directement en mode "détaché", il suffit d'utiliser les options d et m screen -dmS "<titre>" <commande>
Date et heure dans history
echo 'export HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bash_profile source ~/.bash_profile
Watch
watch -n 1 -d "ls -lahs /tmp"
Forcer démontage
forcer démontage
umount -l
fuser -vam /dev/mapper/VGSysteme-LVVarLog
[root@scr5spwba801 vmware-tools-distrib]# df -h
Sys. de fichiers Taille Uti. Disp. Uti% Monté sur
/dev/mapper/VGSysteme-LVRoot
3,0G 378M 2,5G 14% /
tmpfs 939M 0 939M 0% /dev/shm
/dev/sda1 243M 33M 198M 15% /boot
/dev/mapper/VGSysteme-LVHome
504M 17M 462M 4% /home
/dev/mapper/VGSysteme-LVOptDurcissement
124M 5,6M 113M 5% /opt/durcissement
/dev/mapper/VGSysteme-LVOptSoftSysload
1008M 34M 924M 4% /opt/software/sysload
/dev/mapper/VGSysteme-LVOptSoftTina
1,5G 35M 1,4G 3% /opt/software/tina
/dev/mapper/VGSysteme-LVOptSoftVtom
1008M 34M 924M 4% /opt/software/vtom
/dev/mapper/VGSysteme-LVTmp
1,5G 248M 1,2G 18% /tmp
/dev/mapper/VGSysteme-LVUsr
3,0G 609M 2,3G 22% /usr
/dev/mapper/VGSysteme-LVVar
5,0G 424M 4,3G 9% /var
/dev/mapper/VGSysteme-LVVarOptAppli
1008M 34M 924M 4% /var/opt/application
com5snfsa802.admin.recette.justice.local:/var/opt/application/livraisons/scr
985G 429G 506G 46% /opt/livraisons/scr
[root@scr5spwba801 vmware-tools-distrib]# fsck /dev/mapper/VGSysteme-LVVarLog
fsck de util-linux-ng 2.17.2
e2fsck 1.41.12 (17-May-2010)
/dev/mapper/VGSysteme-LVVarLog is in use.
e2fsck: Ne peut continuer, arrêt immédiat.
[root@scr5spwba801 vmware-tools-distrib]# e2fsck -y -f /dev/mapper/VGSysteme-LVVarLog
e2fsck 1.41.12 (17-May-2010)
/dev/mapper/VGSysteme-LVVarLog is in use.
e2fsck: Ne peut continuer, arrêt immédiat.
[root@scr5spwba801 vmware-tools-distrib]# lsof /dev/mapper/VGSysteme-LVVarLog
[root@scr5spwba801 vmware-tools-distrib]# fuser -vam /dev/mapper/VGSysteme-LVVarLog
USER PID ACCESS COMMAND
/dev/mapper/VGSysteme-LVVarLog:
root 1482 F.... auditd
root 29500 f.... snmpd
[root@scr5spwba801 vmware-tools-distrib]#
rsync
rsync -ravin pour voir les fichiers qui seront copiés (le n est pour dry-run)
Cacher Signature Apache/Httpd Sur Red Hat
Fichier /etc/httpd/conf/httpd.conf
ServerSignature On
⇒ ServerSignature Off
ServerTokens OS
⇒ ServerTokens Prod
service httpd reload
http://www.blog.florian-bogey.fr/cacher-la-version-dapache.html
