Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove pattern from filenames

Tags:

unix

rename

how can I remove the word "myfile" in a list of filenames with this structure?

mywork_myfile_XSOP.txt
mywork_myfile_ATTY.txt
mywork_myfile_ATPY.txt

Desired_output:

mywork_XSOP.txt
mywork_ATTY.txt
mywork_ATPY.txt    
like image 562
Fuv8 Avatar asked Dec 18 '13 17:12

Fuv8


Video Answer


1 Answers

The simplest method is to use the common rename command which is available in most Unices.

rename 's/^mywork_myfile_/mywork_/' *

This of course expects you to be on the directory of the files. This will not overwrite files. If you want that, just pass the -f option. Also, take note that there's multiple versions of rename out there which may have different options.

like image 110
carandraug Avatar answered Oct 25 '22 03:10

carandraug