简体   繁体   English

复制和重命名文件-Linux cp命令

[英]Copy and rename files - Linux cp command

I have the following files in my directory. 我的目录中有以下文件。

    tom_aaa.txt  
    tom_bbb.txt  
    tom_ccc.txt 

I want to copy these files and rename them by replacing tom with jerry using shell command (MAC / LINUX /UNIX) 我想复制这些文件并使用shell命令(MAC / LINUX / UNIX)用jerry替换tom来重命名它们

Expected result: 预期结果:

tom_aaa.txt  
tom_bbb.txt  
tom_ccc.txt  
jerry_aaa.txt  
jerry_bbb.txt  
jerry_ccc.txt 

Any suggestions? 有什么建议么?

找到了一种方法。

for i in `ls *`; do cp $i `echo $i | sed "s/tom/jerry/g"`; done

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM