简体   繁体   中英

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)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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