Terminal: Find and copy a file

Discussion in 'Mac Programming' started by rebello95, Nov 3, 2011.

  1. rebello95 macrumors member

    Joined:
    Jun 15, 2011
    Location:
    USA
    #1
    Hey I made an application in AppleScript, and copied some files into the contents folder of the application.

    I need to know how to have terminal find a file in /appname/Contents/File.zip and copy that to another directory.

    PLEASE HELP!
     
  2. r0k macrumors 68040

    r0k

    Joined:
    Mar 3, 2008
    Location:
    Detroit
    #2
    In terminal, do the following:

    Code:
    cd ~
    find . -name "File.zip" -print
    
    CD ~ puts you in your home folder. The find command gives you the path to the files it finds. Now you know where the files are.

    You (more or less) could also do the following:

    Code:
    cd ~
    for f in `find . -name "File.zip" -print`; do
    cp $f ~/destinationfolder
    done
    
    I'm a little rusty on shell script looping syntax and I'm not in front of my Mac so you'll have to do a little trial and error or googling to get the syntax just right.

    hope this helps...
     
  3. rebello95 thread starter macrumors member

    Joined:
    Jun 15, 2011
    Location:
    USA
  4. jiminaus, Nov 3, 2011
    Last edited: Nov 3, 2011

    jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #4
    Or a little more compactly (and little less as though this is a Windows batch script :D)
    Code:
    find ~ -name File.zip -exec cp "{}" ~/destinationfolder \;
    

    EDIT: Grrrr. This thread turned out to be the same as thread, essentially.
     

Share This Page