Copy and rename multiple files in Linux

Copy and rename multiple files from command line based on a pattern.

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

Option g tells sed to search and replace the entire line not to stop after the first occurrence of the search pattern.

If you want only to rename the files use the rename command (the example below search for "searchString" and replace it with "replaceString" in all the file names of the current folder with .ogg extension):

rename 's/searchString/replaceString/' *.ogg

If you want to replace a string which is found multiple times in one file name use the /g modifier:

rename 's/searchString/replaceString/g' *.ogg