2

Since mac doesn't support certain characters like ?!# ... on server directories anymore, I need to find and rename those. There are tons of "Icon?"-files in font folders and I want to rename it to "Icon_"

I tried to do it with terminal since other apps like "a better finder rename" have difficulties to find certain characters like "?" in filenames like my example "Icon?".

My first try was the find command like this:

find . -exec rename -s "Icon?" "Icon_" * {} +

It says "Unknown option: F"

18
  • You are using the wrong quote characters, use " or '. Also, if some characters are not allowed, how would trying to rename these files even work? AFAIK the file system handles these translations automatically, so which problem are you trying to solve here?
    – nohillside
    Commented Jan 20, 2022 at 11:42
  • Also, '?' has special meaning when used to match filenames
    – nohillside
    Commented Jan 20, 2022 at 11:44
  • I have problems to make backups of the servers data. The backup-app errors with those characters. Thanks for the hint with the quotes, your are right, I made the mistake only here in the questions. It's now edited. Commented Jan 20, 2022 at 11:47
  • @ nohillside What special meanings does "?" have? Commented Jan 20, 2022 at 11:49
  • 3
    Just for the record, the chars you specified “?!#” can be used for both filenames and directories. In fact, since unix filenames are stored as arrays of bytes and not characters, with the exception of a small handful of chars, you can use pretty much anything. See: this answer. That said, there seems to be a different issue here to be solved.
    – Allan
    Commented Jul 25, 2023 at 13:21

1 Answer 1

0

In zsh (the shell in mac terminal), you can replace a part of a variable using parameter expansion.

You could try this answer to Rename multiple files based on pattern in Unix, with bash shell command. It would be useful in zsh too.

cd to your target directory, then use:

for f in Icon?* do mv "$f" "${f/Icon?/Icon_}"; done

Since shell command is unforgiving, echo (print) it before you mv (give a new name to) it:

for f in Icon?* do echo "$f" "${f/Icon?/Icon_}"; done

0

You must log in to answer this question.

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