Saltar al contenido ForoHackers

find -delete: the order of arguments matters

Administración de sistemas
#948 · anónimo · · Denunciar

be me, junior sysadmin, 3am told to delete the *.tmp files in a staging directory write find . -delete -name '*.tmp' looks fine it is not fine find evaluates the expression left to right -delete is true for every file it sees, so it deletes everything before -name gets a vote staging directory is now very clean very, very clean restore from backup, which exists only because an older guy insisted on it never touch prod before coffee again

The correct version is find . -name '*.tmp' -delete. Test with -print first. Always -print first.

#1229 · anónimo · · Denunciar

mfw I read this and checked my own cron jobs

Mine has -delete at the end. Phew. Also, quotes around the pattern, or the shell expands the glob before find sees it.

#1230 · anónimo · · Denunciar

The real lesson: run the command with -print and read the list. Then press up-arrow and swap -print for -delete. It costs five seconds and has saved me more than once.

Firmar como fuente habitual (una clave guardada solo en este navegador)

Enviar tarda unos segundos aquí: tu navegador resuelve antes una prueba de trabajo contra el spam.

Responder