Skip to content

Instantly share code, notes, and snippets.

@lpenaud
Last active September 16, 2025 12:56
Show Gist options
  • Select an option

  • Save lpenaud/35e2edcf9126e214275b99fbcff1b5e1 to your computer and use it in GitHub Desktop.

Select an option

Save lpenaud/35e2edcf9126e214275b99fbcff1b5e1 to your computer and use it in GitHub Desktop.
GNU / Linux

Lister les processus qui écoute un port en particulier

sudo lsof -i :80

Récupérer l'identifiant du processus qui écoute un port donné

if [[ "$(ss -tlnp | grep ':3000')" =~ pid=([0-9]+) ]]; then
  echo "${BASH_REMATCH[1]}"
fi

Écouter les changements dans une arboresence

# Bash options: https://www.gnu.org/software/bash/manual/html_node/The-Shopt-Builtin.html
shopt -s extglob globstar nullglob
shopt -u execfail failglob

declare filename

while inotifywait -e modify,move,delete src/**/*.{vue,ts,js}; do
  echo "${filename}"
done < <(read -r filename)

lsof

Lsof est un programme qui permet de lister les flux d'entrée / sortie comme l'ouverture d'un fichier, d'un socket ou l'écoute d'un port...

ss

Un programme pour inspecter les sockets.

Bash

#!/bin/bash
# This script do something unbelievable.
# shopt: https://www.gnu.org/software/bash/manual/html_node/The-Shopt-Builtin.html
# Enable
# extglob : Glob extension
# globstar : Recursive glob with **
# nullglob : Return a empty result if the pattern don't match with files instead of the pattern himself.
shopt -s extglob globstar nullglob
# Disable
# execfail : Stop the process on error.
# failglob : Don't fail if the glob pattern don't match
shopt -u execfail failglob
function main () {
# Do your worse
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment