# cp list of files into another directory

**URL:** <https://community.unix.com/t/cp-list-of-files-into-another-directory/161513>\
**Category:** UNIX for Dummies Questions & Answers\
**Created:** [May 8, 2006, 11:46am UTC](https://community.unix.com/t/cp-list-of-files-into-another-directory/161513 "2006-05-08T11:46:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pavan\_test](https://community.unix.com/letter_avatar/pavan_test/32/5_5575768a8748004e209b776fc1b2916d.png) [@pavan\_test](https://community.unix.com/u/pavan_test)\
**Post date:** [May 8, 2006, 11:46am UTC](https://community.unix.com/t/cp-list-of-files-into-another-directory/161513/1 "2006-05-08T11:46:53Z")

</div>

Hi All,

i am trying to copy files from a directory to another.  
here is what I am doing  
ls -ltr INTER\*  
THE output is list of 80 files.

i have to copy all these 80 files into another directory  
( say /home/pavi/folder) at a time.  
can anyone please suggest me how do I do it.

thanks  
pavi

---

<div class="post-metadata">

**Author:** ![amro1](https://community.unix.com/letter_avatar/amro1/32/5_5575768a8748004e209b776fc1b2916d.png) [@amro1](https://community.unix.com/u/amro1)\
**Post date:** [May 8, 2006, 11:59am UTC](https://community.unix.com/t/cp-list-of-files-into-another-directory/161513/2 "2006-05-08T11:59:29Z")

</div>

Well, there are MANY ways of doing so!  
First and most common is to see if these files have anything in common in their names. If they do you can use the wildcards, something like that: a_file or a???file and so on.  
? stands for any symbol within a name and \* for any numbers of symbols within the name  
Then you simply:  
cp INTER_ /home/pavi/folder, or if the files simply all the files in a directory  
cp \* destinationdirectory

You also can do the same with find and cpio combination and with xargs . While you need to copy between different systems clones cpio works the best as it preserves file attributes (as different systems assign different meanings for options of cp command). If you copy within same machine cp will do just fine.

Get �UNIX Essentials and UNIX Core� DVD if you have questions of this sort.

Hope it helps.

---

<div class="post-metadata">

**Author:** ![DR\_DAVE](https://community.unix.com/letter_avatar/dr_dave/32/5_5575768a8748004e209b776fc1b2916d.png) [@DR\_DAVE](https://community.unix.com/u/DR_DAVE)\
**Post date:** [May 8, 2006, 2:20pm UTC](https://community.unix.com/t/cp-list-of-files-into-another-directory/161513/3 "2006-05-08T14:20:23Z")

</div>

Here is one way:

tar -cf - INTER\* | (cd /home/pavi/folder ; tar -xvf -)

---

<div class="post-metadata">

**Author:** ![pavan\_test](https://community.unix.com/letter_avatar/pavan_test/32/5_5575768a8748004e209b776fc1b2916d.png) [@pavan\_test](https://community.unix.com/u/pavan_test)\
**Post date:** [May 8, 2006, 5:38pm UTC](https://community.unix.com/t/cp-list-of-files-into-another-directory/161513/4 "2006-05-08T17:38:46Z")

</div>

Hi All,

thanks for all your suggestions.  
I have a question;

ls -ltr INTER\*  
( The output is list of 80 files.)

DAT=`ls -ltr $DIR_NAME/INTER* | wc -l`\>/dev/null 2\>/dev/null  
echo " the number of files are $DAT"

cp $DIR\_NAME/INTER\* /home/pavi/folder  
( i have to copy all these 80 files into another directory )

here i want to output may be through an say echo statement that all 80 files have been copied.

can anyone please suggest me how do I do it.

thanks  
pavi

---

<div class="post-metadata">

**Author:** ![jim\_mcnamara](https://community.unix.com/letter_avatar/jim_mcnamara/32/5_5575768a8748004e209b776fc1b2916d.png) [@jim\_mcnamara](https://community.unix.com/u/jim_mcnamara)\
**Post date:** [May 8, 2006, 9:08pm UTC](https://community.unix.com/t/cp-list-of-files-into-another-directory/161513/5 "2006-05-08T21:08:32Z")

</div>

```nohighlight
#!/bin/ksh

let filecnt=0
for file in `ls -1 INTER*`
do
   cp "$file" /other/directory
   let filecnt=$filecnt+1
done
echo "$filecnt files copied"

```
