Terminal - move all files named...

Discussion in 'Mac Programming' started by Aikiman, Nov 13, 2012.

  1. macrumors member

    Aikiman

    Joined:
    Jan 24, 2008
    #1
    I have a whole lot of files that exist in their own directories which in turn exist in a parent directory that I have to copy and move into another directory. Is there a way in terminal that will enable me to look in all the directories inside my current one, search for all files with specified string and wildcard, copy and move into specified directory?
     
  2. Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #2
  3. thread starter macrumors member

    Aikiman

    Joined:
    Jan 24, 2008
    #3
    Thanks for the fast reply :)

    Okay, Inside my current directory I have over 100 child directories. Inside these child directories I have many files but the ones I only need to worry about have a prefix 'ANZ1155...' the rest of the text is unique to the file. I want to be able to make a copy of these files and move them to another directory. I want to be able to do this in one go - so find ALL files with 'ANZ1155' prefix inside child directories, copy and move copies to specified path.

    Hope that is clear.
     
  4. macrumors member

    Joined:
    Jun 17, 2012
    #4
    Assuming you're currently in the parent directory...

    Code:
    find . -type f -name ANZ1155\* -exec cp {} ../destination/ \;
     
  5. thread starter macrumors member

    Aikiman

    Joined:
    Jan 24, 2008
    #5

    That works, thanks a lot guys. (Now I will dissect the code and learn it) :)
     

Share This Page