Linux批处理重命名目录并从名称中删除#字符 [英] linux batch rename directories and strip # character from name

查看:84
本文介绍了Linux批处理重命名目录并从名称中删除#字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含很多子目录的目录,这些子目录的前面有#个:

i have a directory with a lot of subdirectories with a # infront of them:

#adhasdk
#ad18237

我想全部重命名并删除我尝试做的#caracter

I want to rename them all and remove the # caracter I tried to do:

rename -n `s/#//g` *

但似乎没有用。

-bash: s/#//g: No such file or directory

关于此的任何想法。
谢谢

Any ideas on this. Thanks

推荐答案

只用

$ rename 's/^#//' *

使用-n检查您认为它将发生的事情确实发生了。
在您的示例中,您有关于错误消息中使用的错误引号(反引号)的线索

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: s/#//g: No such file or directory

bash试图执行名为 s /#// g

bash is trying to execute a command named s/#//g.

不使用 g (全局),并且不锚定正则表达式,您将替换任何,而不仅仅是第一位置的那个。

No that using g (global) and not anchoring the regular expression you will replace any #, not just the one in the first position.

这篇关于Linux批处理重命名目录并从名称中删除#字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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