Étiquette : find

19 juillet 2015 /

Pour rechercher et archiver les fichiers du répertoire courant:

find . -type f -print0 | tar -czvf backup.tgz --null -T -

Pour rechercher et archiver tous les fichiers .jpg du répertoire courant:

find . -name "*.jpg" -print0 | tar -czvf backup.tgz --null -T -

12 juin 2015 /

[pastacode lang= »bash » manual= »tree%20-L%201%20%2Fetc%20%3E%20arborescence.txt » message= »Si la commande tree est disponible (1 pour 1er niveau, etc…) » highlight= » » provider= »manual »/]

[pastacode lang= »bash » manual= »find%20%2F%20%7C%20sed%20’s%2F%5B%5E%2F%5D*%5C%2F%2F%7C%20%2Fg%3Bs%2F%7C%20*%5C(%5B%5E%7C%20%5D%5C)%2F%2B—%20%5C1%2F’%20%3E%20arborescence.txt » message= »Pour lister une arborescence intégrale » highlight= » » provider= »manual »/]

[pastacode lang= »bash » manual= »find%20.%20-maxdepth%203%20%7C%20sed%20’s%2F%5B%5E%2F%5D*%5C%2F%2F%7C%20%2Fg%3Bs%2F%7C%20*%5C(%5B%5E%7C%20%5D%5C)%2F%2B—%20%5C1%2F’%20%3E%20%2Fhome%2Fstarmate%2Farborescence_bis.txt » message= »Pour lister une arborescence jusqu’au niveau 3″ highlight= » » provider= »manual »/]

[pastacode lang= »bash » manual= »alias%20tree%3D’pwd%3Bfind%20.%20-path%20.%2Fnode_modules%20-prune%20-o%20-print%20%7C%20sort%20%7C%20sed%20’%5C »1d%3Bs%2F%5E%5C.%2F%2F%3Bs%2F%5C%2F%5C(%5B%5E%2F%5D*%5C)%24%2F%7C–%5C1%2F%3Bs%2F%5C%2F%5B%5E%2F%7C%5D*%2F%7C%20%2Fg’%5C »' » message= »Un autre exemple via un alias » highlight= » » provider= »manual »/]

10 juin 2015 /

Il peut-être utile de compter le nombre de fichier dans un répertoire.

Pour compter récursivement le nombre de fichiers du répertoire /home/starmate:

find /home/starmate -type f | wc -l

Ça marche aussi pour les dossiers :

find /home/starmate -type d | wc -l

Ou encore par propriétaire:

find /home/starmate -user starmate | wc -l

Voici les autres options:

-name Recherche par nom de fichier.
-type Recherche par type de fichier.
-user Recherche par propriétaire.
-group Recherche par appartenance à un groupe.
-size Recherche par taille de fichier.
-atime Recherche par date de dernier accès.
-mtime Recherche par date de dernière modification.
-ctime Recherche par date de création.
-perm Recherche par autorisations d'accès.
-links Recherche par nombre de liens au fichier.