0
Main_Directory
     |
Event_Subdirectories
     |
*.mcp .otherfiles

I want to copy all Event_Subdirectories to another Main_Directory that have the *.mcp file within the Event_subdirectory, but I'm unsure how to do that. Do I use rsync?

2

rsync

With rsync it should be fairly easy to do, though not complete.

Assuming ./new_Main_Directory exists, otherwise mkdir ./new_Main_Directory

rsync -a --include '*/' --include '*.mcp' --exclude '*' Main_Directory/ new_Main_Directory/

This would copy only the *.mcp files and the directory structure they lie in. You can always test rsync commands with the --dry-run option.

Source: http://ubuntuforums.org/showthread.php?t=763833

cp

If you want to use cp, you can try something like the following.

for d in ./*/; do
set -- "$d/"*.mcp
if [ -e "$1" ]; then
   # there is at least one .mcp file in $d
   cp -rp -- "$d" ./new_Main_Directory/
fi
done

Source: Find and copy directories containing file type

0

The rsync command didn't really work, but the little for loop script worked perfectly. It copied some other random files, but those were deleted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.