Question

Im trying to rename files on my server to remove special characters (whitespace, æøå, etc) from the filenames. The problem is that i cannot get the rename-function to work. On my local machine the rename function works as expected

rename 's/[^a-zA-Z\.0-9]*/_/g' *.mp3 

renames all files and removes special characters.

On the server, however, the above call has no effect whatsoever. ALso, there is no error message. There is no man-pages-available for the rename-function on the server, and when I try

rename --help
call: rename from to files...

...the helpfull message "rename from to files" ...

Any suggestions? The shell on the server (running ) is some sort of jailshell, the server is running parallells - stuff and cpanel (if that helps)... regards

Was it helpful?

Solution

Create a script called renamer.sh:

dname=$(dirname "$1")
bname=$(basename "$1")
clean=$(tr -dc 'a-zA-Z.0-9' <<< "$bname")
mv "$1" "$dname/$clean"

And use find:

find -type f -name '*.mp3' -exec sh renamer.sh {} \;

OTHER TIPS

@jonasfh: The cpanel jailshell is usually installed on top of centos hosts. Now you can look up rename from the redhat util-linux package, which is not the usual perl script with extended regular expressions you are trying to do, just the simple redhat rename.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top