linux批量重命名目录并从名称中删除#字符
我有一个目录,其中有很多子目录,它们前面有一个 #:
#adhasdk
#ad18237
我想将它们全部重命名并删除 # 字符 我尝试这样做:
rename -n `s/#//g` *
但似乎没有成功。
-bash: s/#//g: No such file or directory
对此有任何想法。 谢谢
i have a directory with a lot of subdirectories with a # infront of them:
#adhasdk
#ad18237
I want to rename them all and remove the # caracter
I tried to do:
rename -n `s/#//g` *
but didn't seem to work.
-bash: s/#//g: No such file or directory
Any ideas on this.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
只需使用
use -n 来检查您认为会发生的事情是否真的发生了。
中使用了错误的引号(反引号)
在您的示例中,您可以了解到错误消息bash is attempts toexecute a command named
s/#//g
。不,使用
g
(全局)并且不锚定正则表达式,您将替换任何#
,而不仅仅是第一个位置的。Just use
use -n just to check that what you think it would happen really happens.
In you example you have the clue about the wrong quotes used (backticks) in the error message
bash is trying to execute a command named
s/#//g
.No that using
g
(global) and not anchoring the regular expression you will replace any#
, not just the one in the first position.我不知道这是否只是您在此处键入时的拼写错误,但是“重命名”命令应该起作用,如果:
内容“-n”告诉它不做任何事情。反引号是错误的(它们意味着一些东西,但不是你想要的)。
I don't know whether it's just a typo when you typed it here, but that "rename" command should work if:
The "-n" tells it to not really do anything. The back-quotes are just wrong (they mean something but not what you want here).
问题是您使用了反引号 (`)。您应该使用正常的引号:
The problem is that you use backticks (`). You should use normal quotes:
我必须重命名给定文件夹内的所有文件夹。每个文件夹名称在圆括号内都有一些文本。以下命令删除了所有文件夹名称中的圆括号:
rename 's/(.+)//' *
I had to rename all folders inside a given folder. Each folder name had some text inside round braces. The following command removed the round braces from all folder names:
rename 's/(.+)//' *
某些发行版不支持
rename
中的正则表达式。您必须安装prename
。更重要的是,有时您无法安装prename
,而必须安装gprename
才能获得二进制prename
。如果您有“prename”,那么只需将反引号字符“`”更改为单引号,一切就应该可以工作。
所以解决方案应该是:
或者
Some distros doesn't support regexp in
rename
. You have to installprename
. Even more, sometimes you can't installprename
and you have to installgprename
to have binaryprename
.If you have 'prename' then just change backtick character " ` " to single quote and everything should work.
So the solution should be:
or