DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Move Files Using Find And Exec

09.26.2007
| 7345 views |
  • submit to reddit
        
find . -name "xyz*" -exec bash -c "mv {} ./xyz-dir/" \;
    

Comments

Snippets Manager replied on Tue, 2008/08/26 - 5:42pm

You might want to preserve the argument to "exec" by quoting the braces '{}', especially if the file name contains any spaces, e.g.: #! /bin/sh # Deletes all mail in users 'Deleted Items' directories that are older than 30 days. find /cygdrive/g/box/ -mindepth 4 -mtime +30 -wholename '*Deleted Items*.MSG' -exec bash -c "mv '{}' /cygdrive/f/OldDeletedItems" -fprint Deleted.log \; Without this I get unexpected results with the directory names containing spaces. Hope this helps someone :)