[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Argument list too long



Dobai-Pataky Balint <dpblnt@xenzor.ro> writes:

> i have a webcam logging all motion into jpgs, my php code does lots with
> it, except after i convert selected jpgs copied into the workin' folder,
> and after conversion i'd like to rm them from php or by hand it'll give:
> rm *.jpg
> su: /bin/rm: Argument list too long
>
> so i have to enter mc, enter the directory and F8 them out.
>
> how could i do a right rm?
> (without generating a shell pattern to rm them in separated groups)

You could use find/xargs; xargs' purpose in life is to break up
command lines like this.  Maybe

  find . -name . -o -type d -prune -o -type f -name '*.jpg' -print0 |
  xargs -0 rm

(untested) to find JPEG files in the current directory, but not
subdirectories, and remove them.  Alternatively,

  find . -type f -name '*.jpg' -print0 | xargs -0 rm

will find JPEG files in the current directory and all subdirectories
and remove them.  With fewer files, I'd advocate trying something like

  find . -type d -prune -o -type f -name '*.jpg' -print

first to non-destructively check that it's getting the right list of
files, then tack on the 'xargs rm' afterwards; sanity checking the
find command's output can't hurt here.

-- 
David Maze         dmaze@debian.org      http://people.debian.org/~dmaze/
"Theoretical politics is interesting.  Politicking should be illegal."
	-- Abra Mitchell



Reply to: