problemas con “find […] -exec […]”
A menudo tenemos la necesidad de hacer ‘algo’ con cada fichero devuelto por una busqueda de find. ¿Verdad o verdad? Pues bien si miras man find encontraras algo como esto:
-exec command ;
Execute command; true if 0 status is returned. All following arguments to find are taken to be arguments to the command until an argument consisting of `;' is encountered. The string `{}' is replaced by the current file name being processed everywhere it occurs in the arguâments to the command, not just in arguments where it is alone, as in some versions of find. Both of these constructions might need to be escaped (with a `\') or quoted to protect them from expansion by the shell. See the EXAMPLES section for examples of the use of the `-exec' option. The specified command is run once for each matched file. The command is executed in the starting directory. There are unavoidâable security problems surrounding use of the -exec option; you should use the -execdir option instead.
Muy bonito verdad? Pues no funciona! El ejemplo mas simple:
find / -name “*log*” -exec echo{} ;
que busca los ficheros que tengan un yy en su nombre y nos muestre el nombre. No funciona de ninguna manera.
El truco, despues de buscar, leer y experimentar es una ‘\‘ antes de los ‘;‘. Con eso da por cerrado el comando y puede ejecutarlo.
Ahora buscar la cadena DisplayName en cada fichero del sistema que tenga vmx es tan facil como:
find / -name “*vmx*” -print -exec grep -i DisplayName {} 2>/dev/null \;
If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

[..]Both of these constructions might need to be escaped (with a `\’) or quoted to protect them from expansion by the shell. [..]