I've got a file script thet deletes about half millions of files, and i want those files to be printed in a log file as an evidence those files were removed.
Invoking the rm utility once for each of half a million times is going to be a LOT slower than invoking the rm utility fifty thousand times with each invocation removing 100 files.
Although not in the standards, many implementations of the rm utility have a "verbose" option such that adding a -v option to each invocation of rm will print the name of each operand removed after it is removed. If you would tell us what operating system and shell you're using, we might be able to make an easy suggestion that would work in your environment.
How did you get the list of 500,000 files to be removed? If you create the list using find, you could have find remove the files instead of just list files to be removed. If the names of the files are in another file, xargs could be used to create groups of files to be processed by rm .
You have given us very little information about your environment. The less information we have, the fewer options we can suggest to solve your problem. Please help us help you.
[pmba1@PRODPMBA3 shell]$ uname -s
Linux
[pmba1@PRODPMBA3 shell]$ uname -a
Linux PRODPMBA3 2.6.18-238.el5 #1 SMP Sun Dec 19 14:22:44 EST 2010 x86_64 x86_64 x86_64 GNU/Linux
2nd How did i get the list of 500,000 files to be removed?
As already suggested by Don Cragun, you might consider piping you list of files into xargs which will group them into fewer actual rm commands. Using the -t flag writes the command being executed to standard error before executing it so you can capture that to a file for review later. It might give you lots of output on few lines, but you can probably make that more readable later on.
You could limit the number of files it processes at once with the -n flag, but that might increase the number of rm command calls and therefore slow your execution. The extreme would be something like:-
One might expect that your xargs man page might say something like:
n number Invoke utility using as many standard input arguments as possible, up to number (a
positive decimal integer) arguments maximum. Fewer arguments shall be used if:
� The command line length accumulated exceeds the size specified by the s
option (or {LINE_MAX} if there is no s option).
� The last iteration has fewer than number, but not zero, operands remaining.