Fuv8
Fuv8

Reputation: 905

Move files according to a specific pattern in the file name

I have to copy a list of files having the following pattern in the name: "_my_file" from sub-folders into one main folder. File names appear as the following:

A_my_file.txt
B_my_file.txt
C_my_file.txt

I used the following string but it does not work:

find . -name "*_my_file*" -exec mv "{}"./dest_fld \;   

Upvotes: 2

Views: 1381

Answers (1)

falsetru
falsetru

Reputation: 368954

Add space between "{}" and ./dest_fld:

find . -name "*_my_file*" -exec mv "{}" ./dest_fld \;   
#                                      ^

It would be better dest_fld to be outside the currently directory. Unless, dest_fld will be scaned too.

Upvotes: 3

Related Questions