If you need to rename files recursively, i.e. rename all files in a directory tree starting from the current directory, you need to wrap the command in find
. Here is a simple version which works if you have Bash available.
find . -d -name "*'*" -exec bash -c $'for f; do
mv "$f" "${f//\\\047/}"; done' _ {} +
If you don't have Bash, you need something like
find . -d -name "*'*" -exec sh -c 'for f; do
mv "$f" "$(echo "$f" | tr -d \'\'')"; done' _ {} +
which is slightly more expensive because it runs an external tr
command for each file. (Also, the quoting here is mildly challenging, to get a literal single quote passed as the argument to tr
inside a shell script in single quotes.)
The -d
option to instruct find
to do a depth-first search is important because it prevents you from attempting to rename a file whose parent directory has been renamed slightly earlier, which would fail because the old path no longer exists under the original name.
(The newline in the middle of the command is just for improved legibility on small screens; you can make it a one-liner if you like.)
The wildcard "*'*"
targets all files with a single quote in them; if you only want to process "*'*.mp4"
or "*'*.mp4'"
then obviously use one (or both) of those wildcards instead. Here's how you can combine them:
find . -d \( -name "*'*.mp4" -o -name ""*'*.mp4" \) -exec ...