Saturday, February 11, 2012

Renaming files (space to underscore) (rename)


###################
# Using 'rename'
###################

rename 's/\s/_/' * <--- for ubuntu
rename " " "_" *  <---- for fedora

For example, to rename all files matching "*.bak" to strip the extension, you might say
rename 's/\.bak$//' *.bak

To translate uppercase names to lower, you'd use
rename 'y/A-Z/a-z/' *

###################
# Using 'mv'
###################

for FILE in *; do mv -- "$FILE" "`echo $FILE | sed 's/ /_/g'`"; done