0

I have a large number of folders, each of which containing multiple subfolders. Something like this

/mnt/data1/Folder1/subjfolder1, /mnt/data/Folder1/subjfolder2, /mnt/data/Folder1/subjfolder3
/mnt/data1/Folder2/subjfolder1, /mnt/data/Folder2/subjfolder2, /mnt/data/Folder2/subjfolder3
...

I like to copy Folder1, Folder2, etc. but only the subjfolder2 in each folder to a new location, say data2. Something like this:

/mnt/data2/Folder1/subjfolder2
/mnt/data2/Folder2/subjfolder2
...

I don't want to copy the entire content of Folder1,2 etc, just the subjfolder2 in each folder. I hope this is clear. Could someone help?

1 Answer 1

0

This kind of thing can be done with simple shell globs:

cp -rt path/to/destination/ /mnt/data2/Folder?/subjfolder2

(matches names in which Folder is followed by any single character)

cp -rt path/to/destination/ /mnt/data2/Folder[0-9]/subjfolder2

(matches names in which Folder is followed by any single decimal digit)

cp -rt path/to/destination/ /mnt/data2/Folder*/subjfolder2

(matches names in which Folder is followed by any string).

Alternatively, to match a specific set of folders you could use brace expansion

cp -rt path/to/destination/ /mnt/data2/Folder{1..17}/subjfolder2
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .