Command line: piping find results to rm

前端 未结 4 1206
时光取名叫无心
时光取名叫无心 2020-12-07 07:19

I\'m trying to work out a command which deletes sql files older than 15 days.

The find part is working but not the rm.

rm -f | find -L /usr/www2/bar/         


        
4条回答
  •  北海茫月
    2020-12-07 08:18

    Assuming you aren't in the directory containing the *.sql backup files:

    find /usr/www2/bar/htdocs/foo/rsync/httpdocs/db_backups/*.sql -mtime +15 -exec rm -v {} \;
    

    The -v option above is handy it will verbosely output which files are being deleted as they are removed.

    I like to list the files that will be deleted first to be sure. E.g:

    find /usr/www2/bar/htdocs/foo/rsync/httpdocs/db_backups/*.sql -mtime +15 -exec ls -lrth {} \;
    

提交回复
热议问题