in reply to Renaming bunches of files

How about saving a process and coping correctly with oddly named files?
perl -MFile::Copy -e 'for(@ARGV){ $a=$_; s/FOO/BAR/; move($a,$_) }' *F +OO*

Makeshifts last the longest.

Replies are listed 'Best First'.
Re: Re: Renaming bunches of files
by graff (Chancellor) on Aug 08, 2003 at 05:03 UTC
    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 | ..."

      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.