Removing spaces in picture filenames

Every day solutions to every day challenges. + Brilliant stuff

Moderators: b1o, jkerr82508

Forum rules
Please feel free to post your tip it does not have to be advanced. Also ask questions directly related to the tip here. But do not start new threads with questions or ask for help here. That is what the help section is for. forum rules: http://bjoernvold.com/forum/viewtopic.php?f=8&t=568
User avatar
viking60
Über-Berserk
Posts: 9351
Joined: 14 Mar 2010, 16:34

Removing spaces in picture filenames

Postby viking60 » 26 Sep 2014, 10:19

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)
Manjaro 64bit on the main box -Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz and nVidia Corporation GT200b [GeForce GTX 275] (rev a1. + Centos on the server - Arch on the laptop.
"There are no stupid questions - Only stupid answers!"

Return to “Tips & Tricks”