Búsquedes: diferència entre les revisions
Salta a la navegació
Salta a la cerca
(→Find) |
|||
Línia 71: | Línia 71: | ||
o filtrant el tipus de fitxers | o filtrant el tipus de fitxers | ||
find . -name *.html -exec grep 'CADENA' {} \; | find . -name *.html -exec grep 'CADENA' {} \; | ||
=== Funcionament del Find === | |||
find [P L H] [path] [expressio] | |||
* -P(never follow symlinks), -L (follow), -H (follow només les linies de comandes: ex.: find ./ y ./ es un symlink). Ej.: find -P /etc/init.d (sin "/" final). | |||
* Options: | |||
** -maxdepth levels | |||
** -mount (no atravesar fs) | |||
* Tests: | |||
** -amin +-n: fichero accedido hace [más/menos de] n minutos | |||
*** -atime : ídem pero con horas | |||
*** ídem con "c" (change) en vez de "a" (accessed) | |||
** -group | |||
** -user | |||
** -name/-iname | |||
** -perm g=w/0020 | |||
** -regex | |||
** -size n[cwbkMG] | |||
** -type d|f|l|... | |||
** exp1 -o exp2 / -not exp1 | |||
* Actions: | |||
** -delete | |||
** -exec | |||
** -ok command | |||
** -print (default) | |||
Més info a: http://lpi.aluzina.org/wiki/101_103 | |||
== Buscar continguts amb Grep == | == Buscar continguts amb Grep == | ||
grep -r "CADENA" /carpeta | grep -r "CADENA" /carpeta |
Revisió del 13:35, 15 oct 2008
Locate
Actualitzar base de dades amb fitxers del sistema:
updatedb
Buscar fitxer ràpidament:
locate NOM_FITXER
- Busca fitxers/directoris que continguin el string que li passem com a paràmetre.
- Busca a una base de dadess (/var/lib/mlocate/mlocate.db). Cal actualitzarla amb updatedb (root).
- Configuració del que entra en la bd: /etc/updatedb.conf. Conté variables PRUNEFS, PRUNEPATHS (es separa amb espais).
Whereis
- Per un programa, dona informació sobre on està el binari, els manuales, etc.
- -b: busca binaris.
- -m: busca per manuals.
- -s: busca còdi font.
> whereis ls ls: /bin/ls /usr/share/man/man1p/ls.1p.gz /usr/share/man/man1/ls.1.gz
Which
Busca només en el Path
which NOM_FITXER
Ls
(Buscar a la carpeta actual nomes)
ls -las NOM_FITXER
ls -las PART_NOM_FITXER*
Find
Busca a la carpeta actual i també a subcarpetes:
find . -name PART_NOM_FITXER*
Algun sistema necessita cometes en el nom a buscar si s'utilitzen caracters comod:
find . -name "PART_NOM_FITXER*"
Busca a tot el sistema:
find / -name PART_NOM_FITXER*
Buscar també links:
find . -iname PART_NOM_FITXER*
Buscar característiques:
find . -size +1500
Buscar fitxers d'un usuari:
find . -user <userid>
Buscar fitxers amb uns certs permisos
find / -perm /0777 # Té algún dels indicats (convertir a ristra de permisos: rwxrwxrwx. Té algún de los indicats significa tenir algú dels que surten en aquesta ristra. 777 es un mal exemple perque fa match amb qualsevol). find / -perm +0777 # Ídem que "/" (deprecated, evitar-lo) find / -perm 6000 # Match exacte find / -perm -6000 # Té tots els indicats o algén més.
- Sense el 4o bit, no es tindrà en compte.
Executar comandes sobre fitxers trobats:
find /var/log -name "*.txt" -type f -exec chmod 755 {} \;
This command changes the permissions of all files with a name ending in .txt in the directory /var/music. The action is carried out by specifying the option -exec chmod 755 {} \; in the command. For every file whose name ends in .txt, the command chmod 755 {} is executed replacing {} with the name of the file. The semicolon (backslashed to avoid the shell interpreting it as a command separator) indicates the end of the command.
Buscar fitxers que continguin una cadena:
find /tmp -exec grep "search string" '{}' /dev/null \; -print
o bé
find /tmp -exec grep -H "search string" '{}' \; -print
o filtrant el tipus de fitxers
find . -name *.html -exec grep 'CADENA' {} \;
Funcionament del Find
find [P L H] [path] [expressio]
- -P(never follow symlinks), -L (follow), -H (follow només les linies de comandes: ex.: find ./ y ./ es un symlink). Ej.: find -P /etc/init.d (sin "/" final).
- Options:
- -maxdepth levels
- -mount (no atravesar fs)
- Tests:
- -amin +-n: fichero accedido hace [más/menos de] n minutos
- -atime : ídem pero con horas
- ídem con "c" (change) en vez de "a" (accessed)
- -group
- -user
- -name/-iname
- -perm g=w/0020
- -regex
- -size n[cwbkMG]
- -type d|f|l|...
- exp1 -o exp2 / -not exp1
- -amin +-n: fichero accedido hace [más/menos de] n minutos
- Actions:
- -delete
- -exec
- -ok command
- -print (default)
Més info a: http://lpi.aluzina.org/wiki/101_103
Buscar continguts amb Grep
grep -r "CADENA" /carpeta