Possibilité du shell??

Bonjour,
Tout le monde, je suis actuellement entrain de tester plusieurs combinaison pour arriver à mes fins. Ma question est la suivante est-il possible de savoir si un fichier a été rajouté dans un répertoire et si oui lequel ?

Piste explorée :
j'essaye de regarder la dernière modification de ce "Répertoire"
premier problème c'est la comparaison du résultat (avant / maintenant )..

Merci d'avance pour vos conseils et votre temps

3 réponses

  1. salut,

    mkdir mon_repertoire
    lastModif=$(stat -c%y mon_repertoire)
    ##plus tard
    currentStat=$(stat -c%y monRep)
    if test $lastModif -eq $currentStat #je ne mets pas de guillemets car c'est des nombres entiers
    then
       echo "pas de modification de mon_repertoire"
    else
       echo "il y a du nouveau dans mon_repertoire"
       lastModif=$currentStat
    fi

    ne tente pas d'utiliser 'ls', le format d'affichage n'est pas stable
    alors que celui de 'stat', c'est toi qui le choisit!
    0
    1. currentStat=$(stat -c%y mon_repertoire)
      bien sûr!

      pourquoi ne pas introduire une petite fonction pour éviter les coquilles :) , puisque le même code est écrit plusieurs fois
      monStat() { stat -c%y mon_repertoire;}
      lastModif=$(monStat)
      ##plus tard
      currentStat=$(monStat)

      et la suite.
      0
  2. Contributeur
    hello
    trouver tous les fichiers modifiés depuis 2h :
    $ touch -d "2 hours ago" /tmp/x
    $ find ~ -newer /tmp/x
    0
    1. Modérateur
      Si tu tolères l'utilisation d'une fonction blocante, utilise l'appel système inotify
      Voir Inotify Example
      Après quelques modifications des includes de l'exemple fourni dans le lien:
      
      johand@osiris: ~/src/C/inotify $ grep inotify_add  inotify_example.c
        wd = inotify_add_watch( fd, "/tmp", IN_CREATE | IN_DELETE );
      johand@osiris: ~/src/C/inotify $ gcc -Wall -o inotify_example inotify_example.c
      inotify_example.c: In function `main':
      inotify_example.c:69:1: warning: control reaches end of non-void function [-Wreturn-type]
      johand@osiris: ~/src/C/inotify $ ./inotify_example  &
      [1] 7914
      johand@osiris: ~/src/C/inotify $ touch /tmp/truc
      New file truc created.


      Regarder:
      inotify_add_watch (2) - add a watch to an initialized inotify instance
      inotify_init (2) - initialize an inotify instance
      inotify_init1 (2) - initialize an inotify instance
      inotify_rm_watch (2) - remove an existing watch from an inotify instance
      0