posted in technology with 0 comments
I had a file renaming problem, where I wanted to remove the spaces from about a thousand files and folders for easier batch handling (I want to convert my ebook science fiction collection into .epub for reading on my iPod). The solution turned out to be:
for file n *; do mv "$file" "`echo $file | sed -e 's/\ /_/g'`"; done
“For every file here, please move the file while replacing spaces with underscores.” I take every file name and I use
echo in combination with
sed to perform a batch rename.
for rar in *.rar; do mv $rar $(echo $rar | sed 's,[ ]*,_,g'); done
“For every file here, please add an underscore before and after each character in the filename.”
The first removes inconvenience spaces. The second messes your files up. Whoops.