# for-loop-fix-filenames.txt used command line to rename file names in several directories, starting at /mountpoint/directory/: for x in `ls`; do cd $x; fix-filenames; cd /mountpoint/directory/; done --------------------------------------------------------------------------------------- #!/bin/bash ############################################################################################### # 2014_05May_09 - john meister copyright 2014 http://LinuxMeister # script to remove spaces in file names and replace with underscore # cleans up web pages by eliminating special characters and allows sorts to work properly # to use place this script in your path and make it executable, then cd to the directory # and execute by the saved name (fix-filename) - works on Linux and MacOS ############################################################################################### # removes spaces, special characters, slashes, and _-_ but NOT caps ############################################################################################### for f in * do mv -v "$f" `echo $f | tr ' ' '_' | tr -d '[{}(),\!]' | tr -d "\'" | sed 's/&/-n-/g' | sed 's/_-_/_/g'` done ###############################################################################################