Copying files from multiple folders

#1

Hi,

This maybe a very simple for many of you and would like some help.

I have dir with multiple folders each named by date

example:

MSC/
20150702
20150703
20150704
20150705
20150706
20150707
20150708
20150709
20150710
20150711
20150712
20150713
20150714
20150715
20150716
20150717
20150718
20150719
20150720

and these folders have lots of folders inside them. I want to copy all the file but only from 20150710 to 20150720 to to a folder called test.

Can someone help?

#2

Hi,

this will do the trick:

``````find 20150720 20150710 -type f -exec cp '{}' test/ \;
``````

Hope it helps…

Lubos

#3

hi Lubos,

Thank you for replying, I tried this but it only copies from the folders 2 folders you list in your command and does not copy files from the 9 folders in between those.

20150711
20150712
20150713
20150714
20150715
20150716
20150717
20150718
20150719

#4

Thanks Lubo,

Here is what worked, find 201507* -type f -exec cp ‘{}’ test/ ;

simple when you know how…many thx

#5

Hi Israr,

I’m sorry I have misunderstood your original question. I thought that you need those two directories only. Nice solution.

Just for a completeness. If it becomes pain in a long term with your regex, here is another solution which allows you to explicitly exclude any directories from find command’s search. In the example below we are excluding 20150720, 20150710 and test directories from find’s search where all other directories in your current working directory is included:

``````# find . -type f -not -path "./20150720/*" -not -path "./20150710/*" -not -path "./test/*" -exec cp '{}' test/ \;
``````

Hope it helps

Lubos

closed #6

opened #7