L'ordre find permet cercar fitxers per múltiples criteris.
$ find [-H] [-L] [-P] [-D debugopts] [-Olevel] [path...] [expression]
El més habitual:
$ find path expression
On path és el camí a partir del qual cercar un fitxer i expression ens permet indicar els criteris de la cerca.
$ find .
Mostra tots els fitxers del directori de treball (.) i subcarpetes. És equivalent a:
$ find . -print
$ find / -name nom_fitxer
NOTA: Si es vol buscar el fitxer a tot el sistema i no voleu tenir problemes amb els fitxers als qual no teniu permisos de lectura heu d'executar l'ordre com a superusuari
$ sudo find / -type d -name nom_carpeta
$ sudo find / -type f -name nom_carpeta
Per exemple, per mostra les carpetes del directori arrel:
$ find / -maxdepth 1 -type d
S'utilitza l'acció -ls:
$ find / -maxdepth 2 -type d -ls
$ find . -perm 664
find . -type f \( -perm -04000 -o -perm -02000 \)
Consulteu SUID i GUID i LPI_110.1. Realitzar tasques bàsiques de seguretat
find . -perm -2 ! -type l -ls -path "./c-prune
find . -nouser -o -nogroup -print
find . -name .rhosts -print
print és l'opció per defecte.
$ find . -type d -exec file {} \;
$ find . -type f -exec file {} \;
$ sudo find / -inum 6242512 /home/sergi/aborrar/prova/linkdurb /home/sergi/aborrar/prova/b
Fitxers més antics de 30 dies:
$ find /linux2/backups/mysql -type f -mtime +30
Fitxers més antics que demà!?:
find /linux2/backups/mysql -type f -mtime -1
$ find $HOME -mtime 0
$ find . \( ! -regex '.*/\..*/..*' \) -type f -mtime 0
$ find ~ -type f -mmin -90 | xargs ls -l
$ sudo find / -size +100M
Per buscar fitxers d'un grup:
$ find / -group grup1
per buscar fitxers d'un usuari:
$ find / -user usuari
Consulteu Grep#Buscar_un_text_en_el_contingut_de_m.C3.BAltiples_fitxers.
$ find . -iname "*.jpg" -or -iname "*.gif" -or -iname "*.png" -or -iname "*.nef"
$ find . -iname "*.jpg" -or -iname "*.jpeg" -or -iname "*.gif" -or -iname "*.png" -or -iname "*.nef" -or -iname "*.avi" -or -iname "*.mov" -or -iname "*.bmp"
$ find . | awk -F "." '{print $3}';
O millor:
$ find . | awk -F"." '{print $NF}' | sort | uniq | more
$ find / \( -perm -4000 -fprintf /root/suid.txt ’%#m %u %p\n’ \) , \( -size +100M -fprintf /root/big.txt ’%-10s %p\n’ \)
Guarda els resultats al fitxers /root/suid.txt i /root/big.txt.
TODO
Search 'expr' in this dir and below. See also findrepo
find -name '*.[ch]' | xargs grep -E 'expr'
Search all regular files for 'example' in this dir and below
find -type f -print0 | xargs -r0 grep -F 'example'
Search all regular files for 'example' in this dir:
find -maxdepth 1 -type f | xargs grep -F 'example'
Process each item with multiple commands (in while loop)
find -maxdepth 1 -type d | while read dir; do echo $dir; echo cmd2; done
Find files not readable by all (useful for web site)
find -type f ! -perm -444
Find dirs not accessible by all (useful for web site)
find -type d ! -perm -111
Search cached index for names. This re is like glob *file*.txt
locate -r 'file[^/]*\.txt'
find . -type f -exec chmod 644 {} \;
$ sudo find . -type d -exec chmod 755 {} \;
$ sudo find . -type d -exec chmod g+s {} \;