9

We have created a lot folders and files that contains the "<" character.

Is it possible to mass-remove these characters?

0

6 Answers 6

5

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.

  1. Once you have Name Mangler installed, launch it
  2. Drag all of the folder you want to rename into the panel where it says "Drag Files and Folders Here"
  3. On the right choose "Find and Replace"
  4. Enter "<"
  5. Under "Replace with" enter the character you want to replace "<" with or leave blank to remove it
  6. Click "Rename x of x items"

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.

2
  • Gonna try this, hold on! Commented Sep 28, 2014 at 12:55
  • I found this application very useful to change files and folders! Thank you! Commented Sep 28, 2014 at 14:25
22

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
9
  • Is it possible that this command takes a while? I'm doing the dry-run and there is no output after 5 minutes? Commented Sep 28, 2014 at 15:22
  • 1
    @Vinozio, How many directories are you scanning? It should be almost instantaneous if not many. If you're starting at / 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.
    – l'L'l
    Commented Sep 28, 2014 at 15:35
  • It's on a NAS, with 250 GB of Data. Commented Sep 28, 2014 at 15:40
  • 1
    @PubliDesign : mv doesn't delete files, it moves them; with any command in terminal please know what you're doing and the risks of such things beforehand. The first command shown is a "dry-run", meaning you should've executed that first to be certain what it does, as it doesn't touch any files. If you overwrote your files somehow that's nobody's fault but your own...
    – l'L'l
    Commented Apr 11, 2017 at 15:02
  • 1
    @davewoodhall: Do you actually believe "This deleted my files" is useful? – you deleted them, take responsibility perhaps! This question was answered almost three years ago, has nearly 10,000 views and nobody else seems to complain of anything similar. Unfortunately I'd say you messed up somewhere along way, sorry...
    – l'L'l
    Commented Apr 11, 2017 at 19:55
2

What Worked For Me - filenames only

  • I gravitate toward terminal solutions because it's free and I've convinced myself I score style points.
  • I didn't need to remove all special characters, I only had to deal with ..., *, (, ), @ and leading underscores _ in a single directory.

cd /path/to/folder/with/offending/filenames/
for file in ./*
  do mv "$file" "${file//([ *\(\)@_$]|\.\.\.)/}"
done
1

It can be done with shellscript or Automator, but possibly NameChanger might be the simplest option, it's donationware - NameChanger-MRRSoftware

1

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
  • 1
    the -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.
    – nohillside
    Commented Sep 28, 2014 at 14:03
1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .