Operating System - HP-UX
1752800 Members
5814 Online
108789 Solutions
New Discussion юеВ

how to copy files using inputfile with filenames

 
SOLVED
Go to solution
Mark Rossen
Occasional Contributor

how to copy files using inputfile with filenames

I have a file with file names (created with ls)
now i want to copy these files to a new directory. How can i do that
7 REPLIES 7
A. Clay Stephenson
Acclaimed Contributor

Re: how to copy files using inputfile with filenames

Hi Mark:

There are several ways to do this.
A script like this is one:
newdir=/destdir/dir1/dir2
cat filefile | while read fname
do
cp $fname ${newdir}/
done

If it ain't broke, I can fix that.
Marcin Wicinski
Trusted Contributor

Re: how to copy files using inputfile with filenames

Hi,

If you have full paths to the files in your file you can do following:

for i in `cat /path_to_your_file`
do
cp $i /destination_path
done



Later,
Marcin Wicinski
Robin Wakefield
Honored Contributor
Solution

Re: how to copy files using inputfile with filenames

Hi Mark,

cd originaldir
for file in `cat yourfile` ; do
cp $file newdir
done

should do it. Put the "-p" argument after cp to keep the permissions.

Rgds, Robin
Thierry Poels_1
Honored Contributor

Re: how to copy files using inputfile with filenames

yet another option:

cat yourlist | cpio -ocB | (cd /otherdir ; cpio -icvdumB)

good luck,
Thierry.
All unix flavours are exactly the same . . . . . . . . . . for end users anyway.
Praveen Bezawada
Respected Contributor

Re: how to copy files using inputfile with filenames

Hi
You can do

while read eachline;do
cp $eachline newdir
done
...BPK...
Wodisch
Honored Contributor

Re: how to copy files using inputfile with filenames

Hello Mark,

on HPUX most seem to like "tar" more than "cpio", so
it would be something like

cd /source-dir
tar cf - < file.lst | (cd /dest-dir; tar xvf -)

or you could use "xargs" and an additional script like
this:

#!/usr/bin/sh
#copymany: copies all parameters to /dest-dir
cp $* /dest-dir

and then call this from within a line like this:

xargs copymany < file.lst

HTH,
Wodisch
Jim Turner
HPE Pro

Re: how to copy files using inputfile with filenames

Hi Mark,

I'm not sure why you're working from a file of filenames, but try Bill Hassell's famous "puddle move":

cd /olddir
find . | cpio -pudlmv /newdir

If you need specific files, craft a -name argument for the find that will suit your needs.

And just my 2-cents' worth: I prefer cpio. Actually, I'd probably like pax the best if I'd ever take the time to learn the syntax.

All the best,
Jim