Wednesday, March 13, 2013

script to rename directories / files with spaces

here's a small script that normalizes directory names by getting rid of empty spaces in the directory name. Worth is noticing that can be tweaked to remove other unwanted characters:

find  -type d | \ find all the directories 
 grep " "\ get only the ones with a whitespace
 | while read line; do\ 
 mv -i ${line} \
`echo  ${line} | sed 's@ @_@g' `\ replace the space 
; done 

in one line the commands for

normalizing directory names

find  -type d | grep " " | while read line; do  echo "[RUN]: Normalizing directory "${line};  mv -i ${line} `echo  ${line} | sed 's@ @_@g' `; done | m

normalizing filenames

find  *  | grep " " | while read line; do echo "[RUN]: Normalizing filename "${line}; mv -i ${line} `echo  ${line} | sed 's@ @_@g' `; done 

No comments:

Post a Comment