Script to move/delete aged files
Hey all,
i want to create a script which can delete the files older than 7 days but in a slot of 1000. As i have millions of file to delete which i need to perform 1000 files in one slot then next 1000 files and so on. The start state should be 7 days before the present date. I tried deleting all the files after 7 days but it has thrown the below error so want to do it in slot of 1000 files. error : /usr/bin/find: arg list too long usage: rm [-fiRr] file ... Please suggest on this. Thanks, Ankit |
What is the command you tried using? You should be able to use the find command's "-exec" option rather than trying to append all matching files to rm through xargs (or some other similar approach).
|
Below is the command which i am using
find . -type f -mtime +7 | xargs rm |
Try:
Code:
find . -type f -mtime +7 -exec rm {} \; You can also try this script: Code:
#!/bin/bash The script should display the rm commands it would execute. Then, if you are satisfied the script is finding the right files (and will execute the correct rm command), then remove the comment mark ('#') from the rm command and re-run the script to actually delete the files. Keep in mind, that you must run the script from the top directory you wish to work from--because the find command uses the '.' for the path. |
Quote:
Code:
find . -type f -print0 -mtime +7 | xargs -0 rm -vf Code:
find . -type f -print0 -mtime +7 | xargs -0 -i rm -vf {} |
The script was intended to display the actual rm command first--giving an opportunity to review what was going to happen before pushing the "big red button" and enabling the actual rm.
As for simplicity, I still like the one-liner at the beginning of my reply ;) |
:cool: Thanks for the help, it worked.. :)
|
All times are GMT -5. The time now is 10:55 AM. |