批量复制、删除一个文件到多个文件夹下 batch copy or delete same file in different directory

本想通过cp +通配符实现,但是会失败或者通过pipline tube “|” 传参, 比如

IF you want to copy a file to a batch of different directories, like that

 

cp fileA directory* 

通配符测试失败,会失败,Regular exresssion Failed

因此可以使用其它方法实现

首先把目录 有规律的文件夹通过正则表达筛选出来

ls directory* >batch.sh
chmod +x batch.sh

然后vim 编辑

批量在行首加入信息,然后执行脚本即可。

insert text at the head of each line

行首 :%s/^/your_word/

行尾 :%s/$/your_word/

按键操作:

注释:ctrl+v 进入列编辑模式,向下或向上移动光标,把需要注释的行的开头标记起来,然后按大写的I,再插入注释符,比如”#”,再按Esc,就会全部注释了。

删除:先按v,进入visual模式,横向选中列的个数(如”#”注释符号,需要选中两列),再按Esc,再按ctrl+v 进入列编辑模式,向下或向上移动光标,选中注释部分,然后按d, 就会删除注释符号(#)。

PS:当然不一定是shell的注释符”#”,也可以是”//”,或者其他任意的字符;vim才不知道什么是注释符呢,都是字符而已。

使用替换命令:

在全部内容的行首添加//号注释

:% s/^/\/\//g

在2~50行首添加//号注释

:2,50 s/^/\/\//g

在2~50行首删除//号

:2,50 s/^\/\///g

 

如果遇到特殊字符,可用转义字符(Escape String)实现,如"/"

 

:%s/\\/\/

  

Ref:

https://www.cnblogs.com/Dennis-mi/articles/5939635.html

上一篇:The different in public protected private inheritance


下一篇:define different Jieba objects in python file