Find

De Linuxmemo.

(Différences entre les versions)
(Expression)
(Astuces)
 
(5 versions intermédiaires masquées)
Ligne 23 : Ligne 23 :
==Expression==
==Expression==
 +
*Force precedence
  ( expr )
  ( expr )
-
Force precedence.  Since parentheses are special to the shell, you will normally need to quote them.  Many of the examples in this manual page use backslashes for this purpose:  `\(...\)' instead of `(...)'.
 
 +
*négation
  ! expr
  ! expr
-
True if expr is false.  This character will also usually need protection from interpretation by the shell.
+
  -not expr (not POSIX compliant.)
-
  -not expr
+
-
Same as ! expr, but not POSIX compliant.
+
 +
*and
  expr1 expr2
  expr1 expr2
-
Two expressions in a row are taken to be joined with an implied "and"; expr2 is not evaluated if expr1 is false.
 
  expr1 -a expr2
  expr1 -a expr2
-
Same as expr1 expr2.
+
  expr1 -and expr2 (not POSIX compliant.)
-
  expr1 -and expr2
+
-
Same as expr1 expr2, but not POSIX compliant.
+
-
expr1 -o expr2
+
*or
-
Or; expr2 is not evaluated if expr1 is true.
+
  expr1 -or expr2
  expr1 -or expr2
-
Same as expr1 -o expr2, but not POSIX compliant.
+
expr1 -o expr2 (not POSIX compliant.)
 +
*liste
  expr1 , expr2
  expr1 , expr2
-
List;  both expr1 and expr2 are always evaluated.  The value of expr1 is discarded; the value of the list is the value of expr2. The comma operator can be useful for searching for several different types of thing, but traversing the filesystem hierarchy only once.  The -fprintf action can be used to list the various matched items into several different output files.
 
==Astuces==
==Astuces==
 +
*somme de taille de fichiers
  find . -iname "*.mkv" | xargs stat -c %s | awk '{a+=$1;print a}' |tail -1
  find . -iname "*.mkv" | xargs stat -c %s | awk '{a+=$1;print a}' |tail -1
-
Calcul de conversion:
+
*Calcul de conversion:
  kilobytes=$((bytes / 2**10))
  kilobytes=$((bytes / 2**10))
  megabytes=$((bytes / 2**20))
  megabytes=$((bytes / 2**20))
  gigabytes=$((bytes / 2**30))
  gigabytes=$((bytes / 2**30))
 +
 +
*purge des sauvegardes de plus de 30 jours
 +
find . -maxdepth 1 -and -mtime +30 -and -type d -and ! -iname "main" -execdir rm -rf {} \;

Version actuelle en date du 30 mai 2014 à 12:40


find [options] [starting path] [expression]
find . -type d -iname thumbs

[modifier] options remarquables

-maxdepth 1

limite a partée 1 au répertoire courant (non récursif)

-iname "*.gz" 

recherche nominative insensible a la caste

-mtime +30

plus vieux de 30 jour (24h*30)

-exec rm -f {} \; 

suppression du résultat

-execdir cp {} /home/ \;
find . -iname "*.mkv" -execdir cp -v {} /mnt/popcorn/Video/MKV/ \;

Using both basename and full path in find -exec for cp

[modifier] Expression

  • Force precedence
( expr )
  • négation
! expr
-not expr (not POSIX compliant.)
  • and
expr1 expr2
expr1 -a expr2
expr1 -and expr2 (not POSIX compliant.)
  • or
expr1 -or expr2
expr1 -o expr2 (not POSIX compliant.)
  • liste
expr1 , expr2

[modifier] Astuces

  • somme de taille de fichiers
find . -iname "*.mkv" | xargs stat -c %s | awk '{a+=$1;print a}' |tail -1
  • Calcul de conversion:
kilobytes=$((bytes / 2**10))
megabytes=$((bytes / 2**20))
gigabytes=$((bytes / 2**30))
  • purge des sauvegardes de plus de 30 jours
find . -maxdepth 1 -and -mtime +30 -and -type d -and ! -iname "main" -execdir rm -rf {} \;
Outils personnels