Skip to content
Snippets Groups Projects
tips_commands.md 12.3 KiB
Newer Older
  • Learn to ignore specific revisions
  • Giovannoni Laurent's avatar
    Giovannoni Laurent committed
    Commandes utiles
    =========================================
    
    ---------------------------------------------------------------
    ## création de fichiers en doublons pour autoimport par exemple
    for (( i=1 ; i<=1000 ; i++ )); do cp /in/courrier/tessi_videocodage/import/C_0.pdf /in/courrier/tessi_videocodage/import/C_0$i.pdf; done
    
    ---------------------------------------------------------------
    ## Création d'un tar.gz
       tar -zcvf votre_archive.tar.gz votre_dossier/
    
    ---------------------------------------------------------------
    ## Décompresser un tar.gz
       tar -zxvf votre_archive.tar.gz -C votre_dossier_cible/
    
    ---------------------------------------------------------------
    ## Extraire un fichier spécifique d'un tar.gz
    	tar -zxvf indexes_20180429T203402.tar.gz "indexes/45" 
    
    ---------------------------------------------------------------
    
    ## Compression 7z
    7z a -y -mx -t7z zz-Archives.7z zz-Archives/
    
    ---------------------------------------------------------------
    
    ## copier 1 fichier dans n répertoires
       for i in $(ls); do cp sourcefile $i;
    done
      
       autre exemple :  for i in $(ls); do cp
    post-commit $i"/hooks"; done
    
    ---------------------------------------------------------------
    
    ## exécuter plusieurs fois le même fichier php
    for (( i=1 ; i<=10 ; i++ )); do php test_ws_store_resource.php; done
    trouver les fichiers récements modifiés
       
        find /mydir -type f -mtime -1 -print
       
    ---------------------------------------------------------------  
    
    ## Nettoyer des répertoires
      
    find . -type f \( ! -path "./cache/*" ! -path "./views/*" ! -path
    "./styles/*" ! -path "./includes/*" ! -path "./images/*"  \) -atime
    -150 -print 
    
    ---------------------------------------------------------------
    
    ## liste des ports utilisés :
    netstat -ntlp | grep LISTEN
    lsof -i:4444 -> donne les processus écoutant sur ce port  
      
    ---------------------------------------------------------------
    
    ## supprimer tous les répertoires .svn
    find . -name ".svn" -type d -exec rm -Rf {} \;
    Trouver des fichiers plus vieux de 10 jours
    find /srv/backups/gandibackups_from_scp -maxdepth 1 -type f  -atime +10
    
    ---------------------------------------------------------------
    
    ## Recherche une chaine de caractère sur tout le système
    cd /
    grep -r 'info@maarch.org' * > result_search
    
    ---------------------------------------------------------------
    
    ## Suppression de fichier ou de répertoire avec liste d'exclusion depuis ls
    rm -Rf $(ls | grep -v 'wordpress\|phpmyadmin')
    
    ---------------------------------------------------------------
    
    ## Copier une liste de répertoires importante
    ls -1 /home/maarch/source | xargs -i cp -R /home/maarch/source/{} /home/maarch/destination
    
    ---------------------------------------------------------------
    
    ## Compter le nombre d'éléments dans un répertoire
    ls -Al /home/maarch/source | wc -l
    
    ---------------------------------------------------------------
    
    ## Compter le nombre de fichiers XML dans un répertoire et ses sous-répertoires :
    find /opt/maarch/imports/autoimport/CGR_REPRISE_COMPTA -name '*.xml' | wc
    
    ---------------------------------------------------------------
    
    
    ## Trouver tous les fichiers contenant un texte donné
    
    ```bash
    # recherche récursive dans tous les fichiers du dossier actuel et ses sous-dossiers
    grep -Hirn 'texte cherché'
    
    # recherche uniquement dans les XML
    find /var/www/html/ -name '*.xml' -exec grep -Hin 'texte cherché' {} \;
    ```
    
    Pour info les options de `grep` :
    - `-H` : affiche le nom du fichier
    - `-i` : recherche insensible à la casse
    - `-r` : recherche récursive dans tous les fichiers à partir du dossier courant
    - `-o` : affiche uniquement la partie de la ligne correspondant à la recherche et non la ligne entière, utile en cas de très longues lignes
    - `-n` : affiche le numéro de la ligne correspondante
    
    ---------------------------------------------------------------
    
    ## Lister l’arborescence des fichiers avec les droits et propriétaires
    
    ```bash
    tree -finpug
    ```
    
    ---------------------------------------------------------------
    
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
    ## Liste des fichiers avec juste la taille (format lisible) et le nom
    ls -lh | awk '{print $5, $9}'
    
    ---------------------------------------------------------------
    
    ## Remplacer des caractères (tokens) dans plusieurs fichiers  
    sed -i -e "s/PASSWORD_MAIL_DSAF/lemotdepasse\!test/g" *.XML
    
    ---------------------------------------------------------------
    
    ## Remplacer du texte dans une série de fichiers répartis dans des dossiers
    find /var/www/html -type f -exec sed -i 's/5432/5434/g' {} \;
    
    ---------------------------------------------------------------
    
    ## Liste des fichiers créer il y a moins de 12 jours, exclusion de l'extension .cache et du répertoire www/maarch.com/*
    
    sudo find www/ -type f  \( ! -iname "*.cache" ! -iname "*.pyc" ! -iname "*.png" ! -path "www/maarch.com/*"  ! -path "www/demo.maarch.org/entreprise_*" ! -path "www/demo.maarch.org/cilbox/*" \)  -atime -1  > result
    
    sudo find www/ -type f   -atime -5  > result
    
    ---------------------------------------------------------------
    
    ## Tuer tous les processus d'un utilisateur
    ps -aef | grep  ^www-data | awk '{ print "kill -9 " $2 }' | sh
    
    ---------------------------------------------------------------
    
    ## Météo sous invite de commande
    curl wttr.in/nanterre
    
    ---------------------------------------------------------------
    
    ## Signer une applet java avec un certificat 
    openssl pkcs12 -in ~/OS201403208071.pfx -out mypenfile.pem
    
    openssl pkcs12 -export -in mypenfile.pem -out mykeystore.p12 -name "MyCert"
    
    jarsigner -storepass MaarchCertif2014 -tsa http://timestamp.globalsign.com/scripts/timestamp.dll-storetype pkcs12 -keystore mykeystore.p12 NetBeansProjects/maarchCM/dist/maarchCM.jar "MyCert"
    
    cd /home/lgi/NetBeansProjects
    jarsigner  -storepass MaarchCertif2014  -keystore ../mykeystore.p12 -tsa http://timestamp.globalsign.com/scripts/timestamp.dll ../NetBeansProjects/maarchCM/dist/maarchCM.jar "mydomain"
    
    ---------------------------------------------------------------
    
    ## Liste des paquets installés 
    sudo dpkg-query -l | grep xdebug
    
    ---------------------------------------------------------------
    
    ## unzip odt
    zip -0 -X ../my-document.odt
    zip odt
    zip -r ../my-document.odt * -x mimetype
    
    ---------------------------------------------------------------
    
    ## Trouver les derniers fichiers modifiés 
    find /var/www/html/oem/  -not -path '*.svn/*' -mmin -120
    
    ---------------------------------------------------------------
    
    ## Trouver un répertoire
    find / -type d -name 'httpdocs'
    
    ---------------------------------------------------------------
    
    ## Redémarrer réseau
    
    sudo ifdown -a
    
    sudo ifup -a
      
    sudo dhclient
      
    sudo start network-manager
    
    sudo /etc/init.d/network-manager restart
    
    --------------------------------------------------------------
    ## PHP7 Configuring and Switching Versions
    
    Now you have two completely separate versions of PHP installed on your system, so let's have a look at where all the pieces went!
    
    The config files are all in /etc/php/5.6 and /etc/php/7.0 respectively - inside here is where you can configure which extensions are loaded, set the ini settings, and everything else for each version in isolation.
    
    I'm an apache user, and as I mentioned both modules are available. So to switch from one to the other I need to do:
    
    ###switch to php7.1
    sudo a2dismod php5.6
    sudo a2enmod php7.1
    sudo service apache2 restart
    sudo mv /usr/bin/php /usr/bin/php_BAK
    sudo rm /usr/bin/php
    sudo ln -s /usr/bin/php7.1 /usr/bin/php 
    
    ###switch to php7
    sudo a2dismod php5.6
    sudo a2enmod php7.0
    sudo service apache2 restart
    
    ###switch to php5.6
    sudo a2dismod php7.1
    sudo a2enmod php5.6
    sudo service apache2 restart
    sudo mv /usr/bin/php /usr/bin/php_BAK
    sudo rm /usr/bin/php
    sudo ln -s /usr/bin/php5.6 /usr/bin/php
    
    ---------------------------------------------------------------
    ## Get new tags from the remote
    $ git fetch --tags
     
    ## Get the latest tag name
    $ latestTag=$(git describe --tags `git rev-list --tags --max-count=1`)
     
    ## Checkout the latest tag
    $ git checkout $latestTag
    
    ---------------------------------------------------------------
    ## Get last tag of current branch
    git describe --abbrev=0 --tags
    
    ----------------------------------------------------------------
    Increase size of request in apache for REST webservices
    ###LimitRequestFields 32767
    ###LimitRequestFieldSize 12392
    LimitRequestLine 10000000000000000
    
    
    -----------------------------------------------------------------
    ## Docker 
    ### list of local images
    docker images
    ### launch build dockerfile
    docker build . -t maarchcourrier
    ### launch sh for a container 
    docker exec -it  maarchcourrier-develop /bin/bash
    
    -----------------------------------------------------------------
    
    UPDATE users set password = '$2y$10$C.QSslBKD3yNMfRPuZfcaubFwPKiCkqqOUyAdOr5FSGKPaePwuEjG', change_password = 'N' WHERE user_id != 'superadmin';
    UPDATE users set password = '$2y$10$Vq244c5s2zmldjblmMXEN./Q2qZrqtGVgrbz/l1WfsUJbLco4E.e.' where user_id = 'superadmin';
    
    UPDATE users set password = '65d1d802c2c5e7e9035c5cef3cfc0902b6d0b591bfa85977055290736bbfcdd7e19cb7cfc9f980d0c815bbf7fe329a4efd8da880515ba520b22c0aa3a96514cc', change_password = 'Y' WHERE user_id != 'superadmin';
    UPDATE users set password = '964a5502faec7a27f63ab5f7bddbe1bd8a685616a90ffcba633b5ad404569bd8fed4693cc00474a4881f636f3831a3e5a36bda049c568a89cfe54b1285b0c13e' where user_id = 'superadmin';
    
    -----------------------------------------------------------------
    ## probleme langues
    dpkg-reconfigure locales
    
    ## Parcours de toutes les branches et update
    for b in "git branch -r | grep -v -- '->'"; do git branch --track ${b##origin/} $b; done
    for b in "git branch -r | grep -v -- '->'"; do echo $b; done
    
    branches=()
    eval "$(git for-each-ref --shell --format='branches+=(%(refname))' refs/heads/)"
    for branch in "${branches[@]}"; do
        echo $branch
    done
    
    ----------------------------------------------------------------
    gestion de wikijs
    lancement
    node wiki start
    arrêt
    node wiki stop
    
    -----------------------------------------------------------------
    ## gitbook
    gitbook serve
    gitbook build
    
    -----------------------------------------------------------------
    ## mise à jour de develop
    git pull
    npm i
    npm run build-prod
    ## puis passer sql/develop.sql
    
    -----------------------------------------------------------------
    ## git pb de conflits
    git reset --hard HEAD
    git rebase
    git fetch
    
    -----------------------------------------------------------------
    ## supprimer toutes les sockets ouvertes par apache pour postgres
    netstat -anp | grep --regexp="5432" | grep apache2 |  awk -F" " '{print $7}' | awk -F"/" '{print $1}'
    
    
    echo kill $(sudo netstat -anp | grep --regexp="5432" | grep apache2 |  awk -F" " '{print $7}' | awk -F"/" '{print $1}')
    
    -----------------------------------------------------------------
    ## Créer un cluster postgres
    su - 
    mkdir /opt/postgtresql
    chown -R postgres. /opt/postgtresql
    su postgres
    /usr/lib/postgresql/11/bin/initdb -D /opt/postgtresql
    
    ## Succès. Vous pouvez maintenant lancer le serveur de bases de données en utilisant :
    cd /opt/postgresql
    /usr/lib/postgresql/11/bin/pg_ctl -D /opt/postgtresql -l fichier_de_trace start
    -----------------------------------------------------------------
    ## Convertir un pdf en imagette png thumbnails
    convert -thumbnail 800x1200 -background white -alpha remove install/samples/res_attachments/invitation.pdf install/samples/tnl/invitation.png
    
    -----------------------------------------------------------------
    ## add execution mode recursively on .sh extensions
    find /directory/of/interest/ -type f -iname "*.sh" -exec chmod +x {} \;
    
    ----------------------------------------------------------------
    ## classer les 5 fichiers les plus gros du répertoire
    du -ah /home/maarch | sort -n -r | head -n 5
    
    ----------------------------------------------------------------
    ## dupliquer une base de données sur un même serveur
    sudo service postgresql restart
    se connecter à la base par défaut "postgres"
    create database nouvelle_base with template ma_base_a_dupliquer;
    
    ----------------------------------------------------------------
    ## augmenter la taille du disque système à chaud
    https://debian-facile.org/atelier:chantier:redimensionner-la-partition-racine-a-chaud-sans-la-demonter
    
    ----------------------------------------------------------------
    ## trouver le dernier fichier d'un répertoire
    find . -type f -printf '%T@ %p\n' | sort -n | tail -1 | cut -f2- -d" "
    
    ----------------------------------------------------------------
    ## supprimer toutes les lignes d'un fichier contenant "RES_ID : "
    sed '/RES_ID : /d' travailv1.log > travailv2.log