How to rename a bunch of files to eliminate quotes
My iomega NAS uses a Linux-like operating system with a bunch of backup files with filenames in double quotes. Like this:
“Water” -4
“Water” -5
etc. (don’t ask how they got there; They were originally created on Mac)
When I try to copy the file to the backup drive, this causes a problem: the quotes obviously cause the copy to fail. (The built-in copy tool uses rsync, but the version is quite old.) )
Is there a terminal command to rename these files in bulk, just remove the quotes? If this is not possible, is there a command to rename them all at once? The quotes seem to really mess things up (I know: users have been warned!)
Solution
Simple one-line bash code:
for f in *; do mv -i "$f" "${f//[\"[:space:]]}"; done
$f is your current filename, ${f//[\”[:space:]]
} is your bash substring substitution, which stands for: < br/> In this
f
(filename), (replace) these [
\"[:space:
]]
(characters) Nothing left [1].
Note 1: String substitution statement: ${string//substring/replacement}
; Because you do not need to replace the substring with empty, leave /replacement
blank.
Note 2: [\"[:space:]]
is an expr
regular expression.