script for Finding files in a folder and copying to another folder

Hi all,

I have a folder '/samplefolder' in which i have some files like data0.txt, data1.txt and data2.txt.

I have to search the folder for existence of the file data0.txt first and if found have to copy it to some other file; next i have to search the folder for existence of file data1.txt and if found have to copy it to some other file. This has to continue for any number of files (like till data1000.txt).

Please provide some shell script to do the same.

Thanks,

find /some/path -iname "data*.txt" -exec cp \"{}\" /other/path

Hi,

thanks for the reply.

If i do this, it will copy all the data*.txt files in /saome/path to /other/path right ?

Precisely.

My exact requirement is...

Step1: Find if data*.txt files exist in some/path
Step2: If exists, copy the first such file (ex: data0.txt) to other/path
Step3: remove the data0.txt
Step4: Repeat step1

Hope this makes things more clear. Sorry, if i was not very clear in the beginning. :frowning:

Then you could just use 'mv' instead of 'cp':

find /some/path -iname "data*.txt" -exec mv \"{}\" /other/path \;