如何重命名一堆文件以消除引号 [英] How to rename a bunch of files to eliminate quote marks

查看:71
本文介绍了如何重命名一堆文件以消除引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的iomega NAS(使用类似于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:

水" -4

水" -5

等(不要问他们是如何到达的;它们最初是在Mac上创建的)

etc. (don't ask how they got there; they were originally created on a Mac)

当我尝试将文件复制到备份驱动器时,这会引起问题:引号显然导致复制失败.(内置的复制工具使用rsync,但版本比较旧.)

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

推荐答案

简单的单行bash代码:

simple single line bash code:

for f in *; do mv -i "$f" "${f//[\"[:space:]]}"; done

$ f 是您当前的文件名, $ {f//[\"[:space:]]} 是您的bash子字符串替换器,代表:
在此 f (文件名)中,//(替换)这些 [\"[:space:]] (字符),没什么[1].

$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].

注意1:字符串替换语句: $ {string//substring/replacement} ;因为您不需要将子字符串替换为空,所以将/replacement 保留为空白.

NOTE 1: string replacement statement: ${string//substring/replacement}; because you don't need to replace your substring to nothing, leave /replacement to blank.

注意2: [\"[:space:]] expr 正则表达式.

NOTE 2: [\"[:space:]] is expr regular expression.

这篇关于如何重命名一堆文件以消除引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆