Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

copy

Status
Not open for further replies.

krava

Programmer
Jun 4, 2007
48
YU
Hi,

I would like to copy all files, let say all that begins with "file*", from ALL subdirectories into the directory with the same structure of subdirectories.

for example :

dir1--+
|
+--subDir1 --+--subSubDir1
|
+-- subSubDir2
-- subDir2
-- subDir3--+--subSubDir1

into

dir2--+
|
+--subDir1 --+--subSubDir1
|
+-- subSubDir2
-- subDir2
-- subDir3--+--subSubDir1

BUT the idea is not to create structure of subdirectories in dir2 in advance.

I started with:

for fl in `find -type f -name "file*" -print`; do
echo $fl;
done

but realised that I have not created subdirectories in dir2 and copying in that case is imposible. How to create the appropriate subdirectories within for-done cycle?

p.
 
Try looking at cpio. From the 'man' pages
man cpio said:
In copy-pass mode, cpio copies files from one directory tree to
another, combining the copy-out and copy-in steps without actually
using an archive. It reads the list of files to copy from the stan-
dard input; the directory into which it will copy them is given as a
non-option argument.

Ceci n'est pas une signature
Columb Healy
 
hmmm ... sounds good but I have no cpio here and I can not install on computer
 
Ok, if you don't have cpio then something along the lines of

Code:
cd old_dir
find . -name "file.*" | tar -cf /tmp/$$.tar -
cd new_dir
tar -xf /tmp/$$.tar
rm $$.tar

Ceci n'est pas une signature
Columb Healy
 
Which flavor of *nix lacks the cpio command ?
 
Which flavor of *nix lacks the cpio command ?
Perhaps you have tar, haven't you ?
(cd /path/to/dir1; tar -cf - `find . -type f -name 'file*'`) | (cd /path/to/dir2; tar -xf -)
 
there is only 1 mashine in office with Windows...but we have cygwin on it
 
try cp -r (I think cp can recurse into subdirs on cygwin too)

cd /dir1
cp -r * /dir2

see man page for cp command

man cp


HTH,

p5wizard
 
Hi

If it is CygWin, why you can not install [tt]cpio[/tt] ? Just run cygwin_setup.exe and in the "Cygwin Setup - Select Packages" window at the "Utils" category you can find "cpio: A backup and archiving utility".

Feherke.
 
no way ... It sais something like 'dasdasdjhjk administrator fsdfsdljlkj'. Everything is in french and I understand It as you understand what I wrote :) But I gess 'administrator' suggest message like 'you are not a damn administrator so you can not instll anything here hahahaha'....I think this is written
 
My copy of Cygwin doesn't have the man pages but
Code:
cp --help
shows that
Code:
cp -r
is valid

Ceci n'est pas une signature
Columb Healy
 
krava said:
no way ... It sais something like 'dasdasdjhjk administrator fsdfsdljlkj'. Everything is in french and I understand It as you understand what I wrote :) But I gess 'administrator' suggest message like 'you are not a damn administrator so you can not instll anything here hahahaha'....I think this is written

Well some of the posters here do understand/speak French so you might want to cut and paste the exact message...

In the mean time, why don't you try the recursive copy I suggested earlier.


HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top