Clean file names from spaces, convert uppercase to lowercase

Remove white spaces from file name

Script content

remove_spaces is the name of the script

Attention: script file must be executable (chmod u+x remove_spaces)

#!/bin/bash
# replace spaces with underscores
for arg
do

DIR=`dirname "$arg"`"/"
FILE=`basename "$arg"`

  new="${FILE// /_}"
  if [ "$new" != "$FILE" ]
  then
    # test if file already exists
    if [ -e "$DIR$new" ]
    then
        echo File \""$new"\" already exists
    else
      echo moving "$arg" to "$DIR$new"
     mv "$arg" "$DIR$new"
    fi
  fi
done

Calling the script

./remove_spaces /path/to/file\ with\ spaces

Changing uppercase to lowercase in filename

Script content

lowercase is the name of the script

Attention: script file must be executable (chmod u+x lowercase)

#!/bin/bash
# lowercase: Changes input to lowercase.
for arg
do

DIR=`dirname "$arg"`"/"
FILE=`basename "$arg"`

  new=`echo "$FILE" | tr '[A-Z]' '[a-z]'`
  if [ "$new" != "$FILE" ]
  then
    # test if file already exists
    if [ -e "$DIR$new" ]
    then
        echo File \""$new"\" already exists
    else
      echo moving "$arg" to "$DIR$new"
     mv "$arg" "$DIR$new"
    fi
  fi
done

Calling the script

./lowercase /path/to/file_WIth_UPPERcaSE

Adding the scripts to Dolphin contextual menu in KDE

(tested on Kubuntu 12.04)

http://techbase.kde.org/Development/Tutorials/Creating_Konqueror_Service_Menus

Create the file

/home/myUserName/.kde/share/kde4/services/myScripts.desktop

with the following content:

[Desktop Entry]
Type=Service
X-KDE-ServiceTypes=KonqPopupMenu/Plugin
MimeType=all/all
Icon=svg
Actions=remove_spaces;lowercase;
X-KDE-Submenu=My scripts

[Desktop Action remove_spaces]
Name=Remove spaces
Icon=kgpg
Exec=/path/to/scripts/remove_spaces

[Desktop Action lowercase]
Name=Lowercase
Icon=kgpg
Exec=/path/to/scripts/lowercase