fork download
  1. #!/bin/bash
  2.  
  3. # ideone boilerplate - we can't write files in the home directory;
  4. # so create a temporary directory for our files instead
  5. t=$(mktemp -d -t ideone.XXXXXXXXXXXX) || exit
  6. trap 'rm -rf "$t"' ERR EXIT
  7. cd "$t"
  8.  
  9. mkdir main
  10. mkdir -p main/{China,Korea}/{Male,Female} main/England/Female
  11. touch main/{China,Korea}/{Male,Female}/foo main/England/Female/bar
  12.  
  13. find . -type f -ls
  14.  
  15. mkdir destination
  16.  
  17. echo '(Notice that cp -v will refuse to overwrite "foo" with another file with the same name)'
  18. cp -v main/*/Male/* destination || true
  19. ls -l destination
  20.  
Success #stdin #stdout #stderr 0.01s 5304KB
stdin
Standard input is empty
stdout
       16      0 -rw-rw-r--   1 20106    1000            0 Jan 10 10:28 ./main/England/Female/bar
       15      0 -rw-rw-r--   1 20106    1000            0 Jan 10 10:28 ./main/Korea/Female/foo
       14      0 -rw-rw-r--   1 20106    1000            0 Jan 10 10:28 ./main/Korea/Male/foo
       13      0 -rw-rw-r--   1 20106    1000            0 Jan 10 10:28 ./main/China/Female/foo
       12      0 -rw-rw-r--   1 20106    1000            0 Jan 10 10:28 ./main/China/Male/foo
(Notice that cp -v will refuse to overwrite "foo" with another file with the same name)
'main/China/Male/foo' -> 'destination/foo'
total 0
-rw-rw-r-- 1 20106 1000 0 Jan 10 10:28 foo
stderr
cp: will not overwrite just-created 'destination/foo' with 'main/Korea/Male/foo'