Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rename a bunch of files to eliminate quote marks

Tags:

linux

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!)

like image 579
user3238181 Avatar asked Oct 21 '25 02:10

user3238181


1 Answers

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.

like image 168
01e Avatar answered Oct 22 '25 15:10

01e