How To Use Find File to Copy

Forum rules
Before you post please read how to get help
SyntheticShield
Level 1
Level 1
Posts: 39
Joined: Wed Dec 09, 2009 10:20 am

How To Use Find File to Copy

Postby SyntheticShield » Fri Jul 29, 2011 2:45 pm

I know that I can use

Code: Select all

cd `find . -name "filename*" -print`


To change to a directory where a file is. However, how can I use the find file in a script to locate the file and then copy it to another directory?

User avatar
Habitual
Level 12
Level 12
Posts: 4207
Joined: Sun Nov 21, 2010 8:31 pm
Location: Youngstown, Ohio

Re: How To Use Find File to Copy

Postby Habitual » Fri Jul 29, 2011 2:52 pm

cp $(find . -name "filename*" -print) /dir/to/copy/to

There is no need to cd to a directory to find a file however. :wink:

I use find `pwd` myself but here's how it worked on my system:

Code: Select all

find . -name ff.notes
./ff.notes

find `pwd` -name ff.notes
/home/jj/ff.notes

cp $(find `pwd` -name ff.notes) Documents/

find `pwd` -name ff.notes
/home/jj/Documents/ff.notes
/home/jj/ff.notes


Code: Select all

cp $(find . -name ff.notes) Documents/


works too. :)
Windows assumes you're an idiot.
Linux demands proof of it.

SyntheticShield
Level 1
Level 1
Posts: 39
Joined: Wed Dec 09, 2009 10:20 am

Re: How To Use Find File to Copy

Postby SyntheticShield » Fri Jul 29, 2011 2:59 pm

I should have made that a bit clearer. I just cut and pasted from what I was using.

I was using that particular line to move to the directory of an unzipped file after downloading it so that it could be compiled. Ive got a lot to learn and sometimes googling doesnt necessarily provide the clearest of answers. Thanks Habitual for your help.

User avatar
Habitual
Level 12
Level 12
Posts: 4207
Joined: Sun Nov 21, 2010 8:31 pm
Location: Youngstown, Ohio

Re: How To Use Find File to Copy

Postby Habitual » Fri Jul 29, 2011 3:00 pm

You're Welcome.
Windows assumes you're an idiot.
Linux demands proof of it.


Return to “Scripts & Bash”

Who is online

Users browsing this forum: No registered users and 2 guests