I am having a the following directory structure:
Main_Dir
|
-----------------------------------
Subdir1 Subdir2 Subdir3
| | |
--------- --------- ---------
| | | | | | | | |
fo1 fo2 f03 fo1 fo2 f03 fo1 fo2 f03
I want to copy all the subdirectories (Subdir1
, Subdir2
, Subdir3
) to a new folder.
But I only want to copy fo1
and fo2
folders in the new place.
Not sure how could it be done.
Best Answer
If the tree of directories is more than just
..../f03
you can use thisrsync
command to copy everyfo1
&fo2
and exclude every other directory with the namefo*
.When dealing with these types of copy scenarios I always make use of
rsync
and it's--dry-run
&--verbose
switches so I can see what it's going to do without actually having to copy the files.Example
Dry run.
If you want to see some of
rsync
's internal logic as to what is being included/excluded then make use of the--verbose
switch.If you need to exclude other forms of directories you can add multiple excludes.