We Recommend

bash Cookbook: Solutions and Examples for bash Users bash Cookbook: Solutions and Examples for bash Users
bash Cookbook teaches shell scripting the way Unix masters practice the craft. It presents a variety of recipes and tricks for all levels of shell programmers so that anyone can become a proficient user of the most common Unix shell -- the bash shell -- and cygwin or other popular Unix emulation packages.


Posted By

iblis on 01/08/08


Tagged

files perl rename admnistration


Versions (?)


Who likes this?

1 person has marked this snippet as a favorite

soroush


Batch rename files in directory


Published in: Bash 


test with echo instead of mv example removes spaces after dots, replaces spaces with _, removes ' , and -, and finally lowercases filenames

  1. for F in * ; do NF=`echo $F | perl -lne "s/ /_/g; s/\._/./g; s/[',-]//g; print lc"` ; mv "$F" "$NF" ; done

Report this snippet 

Comments

RSS Icon Subscribe to comments
Posted By: jkramer on January 30, 2008

ZSH: for foo in *; mv "$foo" "${${(L)${foo//[,'-]/}//. ##/.}// /_}"

You need to login to post a comment.