# Unix How to combine find and cp

**URL:** <https://community.unix.com/t/unix-how-to-combine-find-and-cp/282518>\
**Category:** Shell Programming and Scripting\
**Created:** [February 9, 2011, 8:14pm UTC](https://community.unix.com/t/unix-how-to-combine-find-and-cp/282518 "2011-02-09T20:14:12Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![lio123](https://community.unix.com/letter_avatar/lio123/32/5_5575768a8748004e209b776fc1b2916d.png) [@lio123](https://community.unix.com/u/lio123)\
**Post date:** [February 9, 2011, 8:14pm UTC](https://community.unix.com/t/unix-how-to-combine-find-and-cp/282518/1 "2011-02-09T20:14:12Z")

</div>

Hi ,i want to find sertain files and copy them with cp in current folder

---

<div class="post-metadata">

**Author:** ![yinyuemi](https://community.unix.com/letter_avatar/yinyuemi/32/5_5575768a8748004e209b776fc1b2916d.png) [@yinyuemi](https://community.unix.com/u/yinyuemi)\
**Post date:** [February 9, 2011, 8:41pm UTC](https://community.unix.com/t/unix-how-to-combine-find-and-cp/282518/2 "2011-02-09T20:41:41Z")

</div>

```nohighlight
find -command -exec cp -command {} \; 

```

---

<div class="post-metadata">

**Author:** ![lio123](https://community.unix.com/letter_avatar/lio123/32/5_5575768a8748004e209b776fc1b2916d.png) [@lio123](https://community.unix.com/u/lio123)\
**Post date:** [February 9, 2011, 8:56pm UTC](https://community.unix.com/t/unix-how-to-combine-find-and-cp/282518/3 "2011-02-09T20:56:56Z")

</div>

Thanks ,how can I do  
find ./ -name "\*.c" -size 10  
cp here(directory)

---

<div class="post-metadata">

**Author:** ![yinyuemi](https://community.unix.com/letter_avatar/yinyuemi/32/5_5575768a8748004e209b776fc1b2916d.png) [@yinyuemi](https://community.unix.com/u/yinyuemi)\
**Post date:** [February 9, 2011, 8:58pm UTC](https://community.unix.com/t/unix-how-to-combine-find-and-cp/282518/4 "2011-02-09T20:58:16Z")

</div>

```nohighlight
find ./ -name "*.c" -size 10 -exec cp . {} \;

```

---

<div class="post-metadata">

**Author:** ![DC\_Slick](https://community.unix.com/letter_avatar/dc_slick/32/5_5575768a8748004e209b776fc1b2916d.png) [@DC\_Slick](https://community.unix.com/u/DC_Slick)\
**Post date:** [February 9, 2011, 9:02pm UTC](https://community.unix.com/t/unix-how-to-combine-find-and-cp/282518/5 "2011-02-09T21:02:17Z")

</div>

```nohighlight
find ./ -name "*.c" -size 10 | xargs cp .

```

alternative

---

<div class="post-metadata">

**Author:** ![lio123](https://community.unix.com/letter_avatar/lio123/32/5_5575768a8748004e209b776fc1b2916d.png) [@lio123](https://community.unix.com/u/lio123)\
**Post date:** [February 9, 2011, 9:03pm UTC](https://community.unix.com/t/unix-how-to-combine-find-and-cp/282518/6 "2011-02-09T21:03:07Z")

</div>

Thanks  
can I specified the destination

---

<div class="post-metadata">

**Author:** ![DC\_Slick](https://community.unix.com/letter_avatar/dc_slick/32/5_5575768a8748004e209b776fc1b2916d.png) [@DC\_Slick](https://community.unix.com/u/DC_Slick)\
**Post date:** [February 9, 2011, 9:06pm UTC](https://community.unix.com/t/unix-how-to-combine-find-and-cp/282518/7 "2011-02-09T21:06:07Z")

</div>

> [@lio123](#):
>
> Thanks  
> can I specified the destination

Before asking give it a try. You'll learn better by experimenting. Just don't experiment with rm or mv. Replace the " . " at the end with the desired destination. The period just means "the directory I'm currently in"

---

<div class="post-metadata">

**Author:** ![lio123](https://community.unix.com/letter_avatar/lio123/32/5_5575768a8748004e209b776fc1b2916d.png) [@lio123](https://community.unix.com/u/lio123)\
**Post date:** [February 9, 2011, 9:08pm UTC](https://community.unix.com/t/unix-how-to-combine-find-and-cp/282518/8 "2011-02-09T21:08:38Z")

</div>

I did ,and then ask again :wall:

```nohighlight
find ./ -name "*.csh" -size 10 | xargs cp ./
find ./ -name "*.csh" -size 1 -exec cp ./tova.bac {} \

```

Thanks

---

<div class="post-metadata">

**Author:** ![DC\_Slick](https://community.unix.com/letter_avatar/dc_slick/32/5_5575768a8748004e209b776fc1b2916d.png) [@DC\_Slick](https://community.unix.com/u/DC_Slick)\
**Post date:** [February 9, 2011, 9:14pm UTC](https://community.unix.com/t/unix-how-to-combine-find-and-cp/282518/9 "2011-02-09T21:14:38Z")

</div>

> [@lio123](#):
>
> I did ,and then ask again :wall:
> 
> ```plaintext
> find ./ -name "*.csh" -size 1 -exec cp ./tova.bac {} \
> 
> ```
> 
> Thanks

tova.bac is the directory name? And it's a subdirectory of the directory you are currently in? If not that won't work. You need a semicolon ; after that last back slash. \;

---

<div class="post-metadata">

**Author:** ![lio123](https://community.unix.com/letter_avatar/lio123/32/5_5575768a8748004e209b776fc1b2916d.png) [@lio123](https://community.unix.com/u/lio123)\
**Post date:** [February 9, 2011, 9:15pm UTC](https://community.unix.com/t/unix-how-to-combine-find-and-cp/282518/10 "2011-02-09T21:15:26Z")

</div>

I tried this to but didnt work  
nova is directory:wall:

```nohighlight
 
find ./ -name "*.csh" -size 1 | xargs cp ./nova

 

```

---

<div class="post-metadata">

**Author:** ![DC\_Slick](https://community.unix.com/letter_avatar/dc_slick/32/5_5575768a8748004e209b776fc1b2916d.png) [@DC\_Slick](https://community.unix.com/u/DC_Slick)\
**Post date:** [February 9, 2011, 9:19pm UTC](https://community.unix.com/t/unix-how-to-combine-find-and-cp/282518/11 "2011-02-09T21:19:18Z")

</div>

Is nova a subdirectory of the directory you're currently in? The period means "in the directory I'm currently in". So "./nova" means nova is a subdirectory of the directory your shell prompt is currently in. You can find your current directory by typing 'pwd' at the prompt. Might want to specify the full path of the destination directory...

---

<div class="post-metadata">

**Author:** ![lio123](https://community.unix.com/letter_avatar/lio123/32/5_5575768a8748004e209b776fc1b2916d.png) [@lio123](https://community.unix.com/u/lio123)\
**Post date:** [February 9, 2011, 9:19pm UTC](https://community.unix.com/t/unix-how-to-combine-find-and-cp/282518/12 "2011-02-09T21:19:52Z")

</div>

I am trying this nova is subdirectory to the directory I am in  
it prints  
cp: Insufficient arguments (1)

```nohighlight
 
find ./ -name "*.csh" -size 1 -exec cp ./nova {}\;

 

```

---

<div class="post-metadata">

**Author:** ![DC\_Slick](https://community.unix.com/letter_avatar/dc_slick/32/5_5575768a8748004e209b776fc1b2916d.png) [@DC\_Slick](https://community.unix.com/u/DC_Slick)\
**Post date:** [February 9, 2011, 9:22pm UTC](https://community.unix.com/t/unix-how-to-combine-find-and-cp/282518/13 "2011-02-09T21:22:14Z")

</div>

```nohighlight
find . -type f -name "*.csh" | xargs cp ./nova

```

Does this work for you?

---

<div class="post-metadata">

**Author:** ![lio123](https://community.unix.com/letter_avatar/lio123/32/5_5575768a8748004e209b776fc1b2916d.png) [@lio123](https://community.unix.com/u/lio123)\
**Post date:** [February 9, 2011, 9:26pm UTC](https://community.unix.com/t/unix-how-to-combine-find-and-cp/282518/14 "2011-02-09T21:26:26Z")

</div>

Another question ,how can I add to all files in sertain directory extention to the name file1,file2  
file1.exe,file2.exe  
I tried this but it doesn work

```nohighlight
 
sed s\" "\.exe\ directory

```

---

<div class="post-metadata">

**Author:** ![DC\_Slick](https://community.unix.com/letter_avatar/dc_slick/32/5_5575768a8748004e209b776fc1b2916d.png) [@DC\_Slick](https://community.unix.com/u/DC_Slick)\
**Post date:** [February 9, 2011, 9:29pm UTC](https://community.unix.com/t/unix-how-to-combine-find-and-cp/282518/15 "2011-02-09T21:29:38Z")

</div>

You can just 'mv' a file so example

```nohighlight
mv foo.txt foo.old

```

Would rename foo.txt to foo.old. Lol ooops you said to all files. Give me a second to get home, I'm driving

---

<div class="post-metadata">

**Author:** ![lio123](https://community.unix.com/letter_avatar/lio123/32/5_5575768a8748004e209b776fc1b2916d.png) [@lio123](https://community.unix.com/u/lio123)\
**Post date:** [February 9, 2011, 9:32pm UTC](https://community.unix.com/t/unix-how-to-combine-find-and-cp/282518/16 "2011-02-09T21:32:09Z")

</div>

No it doesnt work it gives me that .csh must be directory ,do you think that I should switch the order

---------- Post updated at 09:32 PM ---------- Previous update was at 09:30 PM ----------

I have to put extation on 50 files in directory,move its not gona work ☹

---

<div class="post-metadata">

**Author:** ![DC\_Slick](https://community.unix.com/letter_avatar/dc_slick/32/5_5575768a8748004e209b776fc1b2916d.png) [@DC\_Slick](https://community.unix.com/u/DC_Slick)\
**Post date:** [February 9, 2011, 9:53pm UTC](https://community.unix.com/t/unix-how-to-combine-find-and-cp/282518/17 "2011-02-09T21:53:44Z")

</div>

> [@lio123](#):
>
> No it doesnt work it gives me that .csh must be directory ☹

it shouldn't say that .csh must be a directory, we specified ' -type f ' meaning it's a file not a directory. Make sure you type in the command exactly or just copy and paste if your shell allows it. If you specified ' -type d ' then it would be looking for a directory.
