Page 1 of 1

Removing spaces in picture filenames

Posted: 26 Sep 2014, 10:19
by viking60
I am working on a script for a wallpaper changer for Pekwm and Openbox. During this progress I noticed that my script would not show wallpapers with spaces in their names.
Now spaces are pretty common in pic names like 789 56 36.jpg provided by some camera etc.

I could work more on my script but I decided that spaces in filenames are really stupid and will probably cause trouble in other settings too; so I made me a remove spaces from (jpg) pictures script:
rmspace.sh

Code: Select all

IFS="\n"
for file in *.jpg;
do
    mv "$file" "${file//[[:space:]]}"
done

chmod it to execute:

Code: Select all

chmod +x rmspace.sh

Run this in the directory where you have your jpg wallpapers like this:

Code: Select all

./rmspace.sh


Now all the spaces will be removed from you jpg picture names - and it sure beats renaming them one by one +1
(The name stays the same; only the spaces are gone)