My iomega NAS, which uses a linux-like OS, has a bunch of backed-up files on it with filenames containing double quotes. Like this:
"Water"-4
"Water"-5
etc. (don't ask how they got there; they were originally created on a Mac)
This is causing problems when I try to copy the files to a backup drive: the quote marks are apparently causing the copy to fail. (The built-in copy facility uses rsync, but a rather old version.)
Is there a terminal command to batch-rename these files, just deleting the quote marks? Failing that, is there a command to rename them one at a time? The quote marks seem to really be messing things up (I know: the user has been warned!)
simple single line bash code:
for f in *; do mv -i "$f" "${f//[\"[:space:]]}"; done
$f
is your current file name and ${f//[\"[:space:]]}
is your bash substring replacer which stands for:
in this f
(file name), //
(replace) these [\"[:space:]]
(characters) with nothing[1].
NOTE 1: string replacement statement: ${string//substring/replacement}
; because you don't need to replace your substring to nothing, leave /replacement
to blank.
NOTE 2: [\"[:space:]]
is expr
regular expression.
You can loop on the files and use mv
:
for i in *
do
mv "$i" "`echo $i | sed 's/"//'`"
done
Try doing this :
$ rename -n 's/"//' *Water*
and remove the -n
switch when your tests will be OK.
Take care, you need the perl's version of rename, there's sometimes another versions installed depends of your distro. If you don't have it, try to search prename
or visit https://metacpan.org/pod/distribution/File-Rename/rename.PL