in reply to Re: Renaming bunches of files
in thread Renaming bunches of files

If there happen to be lots of files that match the wildcard file-spec, some shells won't be able to handle this sort of command line ("too many args").

Of course, such shells won't handle "ls *FOO*" either, since the shell tries to populate the command line based on the file spec, before running "ls" (i.e. you are certainly correct that "ls" is redundant here).

Sometimes, one must resort to things like "ls | grep FOO | ..."

Replies are listed 'Best First'.
Re^3: Renaming bunches of files
by Aristotle (Chancellor) on Aug 08, 2003 at 16:06 UTC
    find -name '*FOO*' -maxdepth 1 -print0 | xargs -r0 perl -MFile::Copy - +e 'for(@ARGV){ $a=$_; s/FOO/BAR/; move($a,$_) }'
    (Or if you are appalled by the find syntax, it may suffice to
    ls | grep FOO | xargs -r perl -MFile::Copy -e 'for(@ARGV){ $a=$_; s/FO +O/BAR/; move($a,$_) }'
    though that won't cope with pathologically named files.)

    Makeshifts last the longest.