We have created a lot folders and files that contains the "<" character.
Is it possible to mass-remove these characters?
I use Name Mangler 3 for file and folder renaming. There are free options out there, but Name Mangler offers a ton of features that make it well worth the $19.00 to me.
Here is Name Mangler on MacUpdate which includes links to many similar programs.
Once of the many things that makes using a tool like Name Mangler valuable is that you can undo your changes, view a history of your changes, and create a "droplet" that make running the name change on other files really convenient. All of that plus being able to use Regex to build very complicated renames.
There is also a great Name Mangler Google Group where you can get your questions answered and some very advanced features and methods get discussed. They have been a big help to me.
You can do this quite simply and quickly in Terminal:
cd /path/to/start/renaming
find . -name '*\<*' | while read f; do echo mv "$f" "${f//\</}"; done
The command above is a "dry-run" of the command below:
find . -name '*\<*' | while read f; do mv "$f" "${f//\</}"; done
This will remove any <
characters recursively on files and folders starting from the path you cd into initially.
Result:
mv ./<folder<test< ./foldertest
mv ./<test3.txt ./test3.txt
mv ./test2<.txt ./test2.txt
mv ./test<test.txt ./testtest.txt
/
for example it could take a while. Try using the command in a directory where you know there's a file/folder with the <
in the name and see what it does.
..., *, (, ), @
and leading underscores _
in a single directory. cd /path/to/folder/with/offending/filenames/
for file in ./*
do mv "$file" "${file//([ *\(\)@_$]|\.\.\.)/}"
done
It can be done with shellscript or Automator, but possibly NameChanger might be the simplest option, it's donationware - NameChanger-MRRSoftware
You can easily do this with a shell script (free), e.g.:
!#/bin/ksh
for filedirname in `ls -1 *\<*` # Note ls -1(one) not the alphabet L
do
NEW_NAME=$(echo "$filedirname" | sed 's/\<//g')
mv "$filedirname" "$NEW_NAME"
echo "Changed name from $filedirname to: $NEW_NAME"
done
-1
isn't really necessary (ls creates single column output anyway if output is not sent to a screen), also for f in *\<*; do
should work as well.
As a modification of I'L'I's answer, to replace a character to an underscore (or whatever your preference) you can use:
find . -name '*\<*' | while read f; do echo mv "$f" "${f//\</_}"; done
The command above is a "dry-run" of the command below:
find . -name '*\<*' | while read f; do mv "$f" "${f//\</_}"; done
Note 1: You can replace the _ with your chosen character.
Note 2: Because the "<" is a special character, you need to replace place the escape character \
in front of it. If you were trying to replace a different character such as colon :
you would not need the \ in front of it. (The backslash occurs twice on each line above).
Note 3: Be sure to try the dry run first in case something is not quite correct. Also, be sure to back up your files beforehand in case you mistype something.