in reply to Re^6: UNIX command - remove 0 byte file
in thread UNIX command - remove 0 byte file

the whole point of using xargs in this discussion subthread was to get unix to process the list of removals in one go rather than per file. I am not sure if the same effect can be achieved from perl - unlink will accept multiple arguments (so you could push to array before passing the array to unlink), but I don't know if any optimisation is achieved that way.

-M

Free your mind

  • Comment on Re^7: UNIX command - remove 0 byte file

Replies are listed 'Best First'.
Re^8: UNIX command - remove 0 byte file
by Anonymous Monk on Sep 23, 2005 at 15:27 UTC
    xargs was used to eliminate the need to start a different process for each file to be removed. The use of xargs enables you to call rm with a list of file names. But rm will still have to delete the files one by one - the Unix unlink system call accepts only a single argument.

    If you pipe the result of find into perl, you are calling a single process - only one perl instance will be fired. In fact, even less processes will be fired if there are many files to be deleted - xargs will start as many subprocesses as needed to avoid running into system limits with respect to argument lengths. But the perl solution doesn't have that problem, as it's reading the list from standard input, not from @ARGV.