[Risolto] find -exec

ciao…

ho un problema con il mio PC …

ho scritto una semplicissimo bash file che crea le copie di backup giornaliere dei miei docuemnti…

L’unico problema che vorrei limitare le copie a 10 giorni. Cos ho scritto questa funzione:

find /data/backup/ -name '*.tgz' -type f '(' -ctime +10 -o -mtime +10 ')' -exec rm -f {}

E qui ho un problema: la funzione “find” trova automaticamente e correttamente i file pi vecchi di 10 giorni, ma non mi esegue -exec.

L’errore che ritorna e’:

find: manca l'argomento di `-exec'

E non capisco… secondo il manuale mi sembra tutto corretto… l’argomento poi di exec c’e’! Ho provato anche a passargli argomenti banali come “-exec echo ciao” ma ritorna sempre lo stesso errore…

Grazie per un vostro suggerimento…

Mariani

modificala così:

$ find /data/backup/ -name '*.tgz' -type f '(' -ctime +10 -o -mtime +10 ')' |xargs rm -f

se vuoi proprio usare exec, io ho provato ad aggiungere :
find /data/backup/ -name ‘*.tgz’ -type f ‘(’ -ctime +10 -o -mtime +10 ‘)’ -exec rm -f {} ;
cosi ho visto che non mi da più errore

P.S.
Ho notato adesso che se inserisco nel post >>inserisci codice non mi piglia il backslash.
Preciso , dopo l’ultima parentesi graffa dai >>spazio, backslash e;

Signori,

Merci!

Ho provato entrambi e mi sembrano funzionare. Posso magari chiedere a cosa serve il ‘;’ ?

quoto dalle pagine man:

-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 arguments 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**

usare l’opzione -delete di find no eh? :slight_smile:

idea interessante