we have more than 100000 files in a directory which are write-protected regular file, these files are quite old and would like to delete them completely, Kindly let me know the command or peice of code to automate the process.
With that sparse a specification (i.e. NO conditions), a simple crontab entry
0 * * * * rm /path/to/directory/MPNT*.Bobline
to delete the files on the hour might suffice. Please be careful and test the command beforehand (e.g. echo rm /path...) so no serious harm is done on e.g. typographical errors.
I get a prompt before i delete the files, i need to enter y to delete the files which i dont want to do all the time, Can this be automated to make sure all the files are deleted with out manual intervention?
rm: remove write-protected regular file `MPNT_Bulk_2015.07.01-14.40.00.Bobline'? y
rm: remove write-protected regular file `MPNT_Bulk_2015.07.01-14.45.00.Bobline'? y
In addition to what RudiC suggested, with write protected files you may need the rm -f option. And, with 100000 files you could run into ARG_MAX limitations. Note also that it is a bad idea to have spaces in the middle of some of your filenames, but with the code RudiC suggested, or with:
you should be able to handle them with no problem. If you use a while read path loop, be very sure that you use double quotes when you expand "$path" or the spaces in your filenames will cause unfound pathname fragment errors or will remove files other than the ones you are trying to remove.
puser@Polo44 Bobline]$ unalias rm
bash: unalias: rm: not found
[puser@Polo44 Bobline]$ which unalias
/usr/bin/which: no unalias in (/usr/kerberos/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/opt/ACEngsc/bin:/opt/CCOsudo/bin:/opt/dataload/bin:/opt/*/sbin:/opt/ACEngsc/bin:/opt/CCOsudo/bin:/opt/dataload/bin:/opt/*/sbin)
[puser@Polo44 Bobline]$ which rm
/bin/rm
[puser@Polo44 Bobline]$ unalias /bin/rm
bash: unalias: /bin/rm: not found
My server configuration is like below
Linux Polo44 2.6.18-371.4.1.el5 #1 SMP Wed Jan 8 18:42:07 EST 2014 x86_64 x86_64 x86_64 GNU/Linux
just replacing /path/to/directory with an absolute pathname of the directory that contains the thousands of files you're trying to remove.
Any version of bash should include unalias as a built-in, but you don't need it. As I said before, if you don't run into ARG_MAX limits, the command:
rm -f /path/to/directory/MPNT*.bobline
should do what you want (again changing /path/to/directory to an absolute pathname of the directory that contains the thousands of files you're trying to remove).