In realtà si sta tubazioni rm's uscita all'ingresso di find. Quello che vuoi è usare l'output di findcome argomenti per rm:
find -type f -name '*.sql' -mtime +15 | xargs rm
xargsè il comando che "converte" il suo input standard in argomenti di un altro programma o, come più accuratamente lo inseriscono nella manpagina,
costruire ed eseguire le righe di comando dall'input standard
Si noti che se i nomi dei file possono contenere caratteri di spazi bianchi, è necessario correggere ciò:
find -type f -name '*.sql' -mtime +15 -print0 | xargs -0 rm
Ma in realtà, findha una scorciatoia per questo: l' -deleteopzione:
find -type f -name '*.sql' -mtime +15 -delete
Si prega di essere consapevoli delle seguenti avvertenze in man find:
Warnings: Don't forget that the find command line is evaluated
as an expression, so putting -delete first will make find try to
delete everything below the starting points you specified. When
testing a find command line that you later intend to use with
-delete, you should explicitly specify -depth in order to avoid
later surprises. Because -delete implies -depth, you cannot
usefully use -prune and -delete together.
PS Nota che il piping diretto a rmnon è un'opzione, perché rmnon si aspettano nomi di file sull'input standard. Quello che stai attualmente facendo è reindirizzarli all'indietro.