To content | To menu | To search


Extract strings from binary files

Retrouver les chaînes de caractères d'un fichier binaire

strings -a -n 300 -e S a_binary_file.db [1]


[1] Scan all file, set line length to 300, choose a 8-bit character encoding


Optimize execution time of repeated commands

Optimiser l'exécution de commandes répétées


[1] Locally recompile the package from sources, could be any other package, hence command

[2] Prelink ELF shared libraries and binaries to speed up startup time


Mount distant repository via SSHFS

Monter un répertoire distant via SSHFS

  • via sshfs sshfs -o nonempty /mnt/baz
  • via mount, add a /etc/fstab line : /mnt/baz fuse defaults,users,noauto,async,noatime,allow_other 0 0


Recompress images JPEG / PNG at equal quality

Recompresser des images JPEG / PNG sans perte de qualité

  • JPG monotask : find . -name \*.jpeg -exec jpegoptim -pt
  • JPE?G multitask : find . -regextype posix-extended -iregex '.*(jpeg|jpg)' -print0 | xargs -0 -P $((`nproc` / 2)) jpegoptim -pt [1]
  • PNG multitask : find . -name \*.png -print0 | xargs -0 -P $((`nproc` / 2)) -I {} zopflipng -m --lossy_8bit --lossy_transparent -y {} {} [2]


[1] find can accept regex ; See Rip music CD to MP3 or FLAC for -print0 / -0

[2] -I {} permit to choose a replacement token for file names ; here we explicitely set zopflipng calls to overwrite files


Grep some text in some selected files

Trouver du texte dans une sélection de fichiers

find "$3" -name "$2" -print0 | xargs -0 grep -i -n --color $1

  • $1 : text to search
  • $2 : files to find and search in
  • $3 : where to search for files to find
  • find -print0 | xargs -0  : use zeros to separate elements, not spaces, to accept spaces in file names


Immutable directory via chattr, avoid writing in unmounted partition

Rendre un dossier immuable (sans droit d'écriture) via chattr pour éviter d'écrire dans un dossier s'il n'est pas monté.

chattr +i /stockage/backup

Remerciements à /home/lord


Change vim spellcheck language

Changer la langue de la correction orthographique de vi / vim

:setlocal spell spelllang=en_us


Downgrade .deb package with aptitude (force version)

Revenir à une version précédente d'un paquet Debian

Downgrading to an earlier Debian branch is not officially supported. Aptitude is able to compute downgrading dependancies.

aptitude install <pkg>=<version>


Mark package as manually installed

Marquer un paquet comme installé automatiquement

  • apt-mark : apt-mark manual <pkg>
  • aptitude : aptitude unmarkauto <pkg>


List manually installed package in Debian

Lister les paquets installés volontairement dans Debian

  • via apt-mark : apt-mark showmanual
  • via aptitude : aptitude search '~i!~M' -F '%p'


Share folder between KVM virtual machine and Debian host

Partager un dossier entre une machine virtuelle KVM / QEMU et un système hôte Debian

kvm -virtfs local,id=label-a,path=/host/folder,security_model=none,mount_tag=label-a

Then, in the virtual machine :
mkdir /mnt/guest-view
mount -t 9p -o trans=virtio,version=9p2000.L label-a /mnt/guest-view


Rip music CD to MP3 or FLAC

Copier un CD de musique en MP3 ou Flac

CD -> WAV : cdparanoia -d /dev/hda -B
WAV -> MP3 : lame --vbr-new --preset extreme a_file.wav a_file.mp3
*.WAV -> MP3 : for x in `ls *.mp3`; do lame --vbr-new --preset extreme $x "`basename ${x} .wav`.mp3"; done; [1]
*.WAV -> MP3 in parallel : find . *.wav -print0 | xargs -0 -P $((`nproc` / 2)) -I {} lame --vbr-new --preset extreme {} {}.mp3 rename 's/\.wav\.mp3$/\.mp3/' *.mp3 [2]
*.WAV -> FLAC : flac --replay-gain --best *.wav
*.WAV -> FLAC in parallel : find . *.wav -print0 | xargs -0 -P $((`nproc` / 2)) -I {} flac --replay-gain --best "{}"


[1] --print0 / -0 options replace space by zeros at file name ends to deal with spaces in file names ; backticks call a sub-command ; basename isolate main part of name from extension

[2] $(()) for math operations ; backticks nproc for CPU number ; rename files in a second time


Start Tails ISO via KVM virtual machine

Démarrer une ISO Tails dans une machine virtuelle KVM / QEMU

kvm --cdrom tails-amd64-X.Y.iso

To improve performances you can specify available memory and CPU type : -m 2G,slots=2,maxmem=4G -smp 2 -cpu Skylake-Client
To add a USB peripheral : -usb -usbdevice host:534c:0001 [1]
To boot from a virtual drive presented as a removable USB key : -device piix3-usb-uhci -drive id=a,file=tails-storage.qcow2,if=none,format=qcow2 -device usb-storage,drive=a,removable=on
To create a KVM virtual drive : qemu-img create -f qcow2 -o size=5G tails-storage.qcow2


[1] With host definition found in /var/log/syslog


Mount Bluetooth peripherals (such as Android 7 phones)

Monter un périphérique Bluetooth comme un téléphone Android 7.

  • Mount : obexfs -b MAC_address_of_peripheral /mountpoint [1]
  • Unmount : fusermount -u /mountpoint [2]


[1] MAC_address_of_peripheral, such as : 84:CF:BF:8F:46:E1

[2] Works even if you first failed by other way of unmounting


Change automatic stop connection delay for SSH sessions

Changer le délais de déconnexion automatique pour les sessions SSH.

  • echo $TMOUT [1]
  • export TMOUT=600 [2]
  • export TMOUT= [3]


[1] Check if timeout is set in the distant machine shell (Bash, Zsh…)

[2] Set a session timeout of 10 minutes

[3] Disable session timeout

- page 2 of 4 -