Consider I have the following file structure. Where “main” is the directory and the following are the subdirectories under it. For example, China is a subdirectory under main and Male and Female are subdirectories under China
main
- China
- Male
- Female
- Korea
- Male
- Female
- England
- Male
- Female
.
.
.
(so on)
Now I want to copy the contents of the subdirectories named “Male” which are under main to another location. Is there any command for it? Can someone help me with this. Thanks.
I tried
cp main/*/Male/* destination
, but this will fail if there is no such subdirectory named “male” for some directories under main
Write a script.
for i in main/*/Male/*; do ......
Your diagnostics are incorrect. There will be no error; it will simply fail to match any directories which … don’t match. Demo: ideone.com/gfh21W