Saturday, September 17, 2011

Perl one liner to rename files


Where aaa is the pattern we want to replace with bbb

ls | perl -ne 'chomp; next unless -e; $o = $_; s/aaa/bbb/; next if -e; rename $o, $_';

at the /g to search all the string (replace more than once)

ls | perl -ne 'chomp; next unless -e; $o = $_; s/aaa/bbb/g; next if -e; rename $o, $_';

originally posted with a list of other perl one liners.