|
Home > Archive > Unix Shell > October 2005 > using find and copy to copy directories
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
using find and copy to copy directories
|
|
| writetosmacky@gmail.com 2005-10-24, 3:45 pm |
|
Hi,
I am trying to copy some specific directories over to another
directory, using the find and cpio or copy commands. I am working in a
directory that is two directories above the directories that I need to
copy (I have to copy multiple directories within different
directories). Each dir structure looks like this:
data(my working directory)
|
dir1
|
dir2
|
RAWdirectory(and contents)that-I-need-to-copy
I tried doing this:
find . -name '*RAW' -depth -print | cpio -pdumv target_dir/
and I also tried this:
find ././* -name '*RAW*' -depth -print | cpio -pdumv target_dir/
These commands will copy the directories I need to the target
directory, but ALSO copy the two directories above each RAW directory,
which I do not want to copy. Does anyone know how to copy directories
that are *inside* other directories *without* copying the directories
that they are nested in?
thanks,
PC
| |
| writetosmacky@gmail.com 2005-10-24, 3:45 pm |
| P.S. I should also add that I don't believe my version of Unix supports
the -mindepth -maxdepth options.
| |
| johngnub 2005-10-24, 3:45 pm |
| Silly question?
What are the names of the files in the dir, do they have a pattern that
maybe a regex can catch. Like find . -name "a[0-9]*.raw" ( for a file
named a2.raw. ), add in the -type option to find only "files" ( -type f
).
Food for thought......JB
| |
| writetosmacky@gmail.com 2005-10-24, 3:45 pm |
|
*sigh* -- TGIF.
Thanks for your help, John!
-PC
| |
| writetosmacky@gmail.com 2005-10-24, 3:45 pm |
|
JB,
I figured out why a simple 'copy' wasn't working to begin with....a
stupid oversight on my part. Thanks for your suggestion, anyway!
-PC
| |
| Michael Paoli 2005-10-24, 3:45 pm |
| How about something like this, for Bourne and compatible shells, and
using GNU find and GNU cpio:
$ (cd dir1/dir2 && find RAWdirectory -depth -print0 |
cpio -0pdmu ../../target_dir)
If you're not using GNU find and GNU cpio remove the 0 from the find
and cpio options, and take appropriate measures to consider and/or deal
with pathnames in/under RAWdirectory that may contain newline - e.g.
you could filter those out with find with suitable inclusion of -name
'*
*' and some logic (e.g. -prune) if you want, or use some other means to
copy them, such as tar, e.g.:
$ (cd dir1/dir2 && tar -cf - RAWdirectory) |
(cd target_dir && tar -xf -)
In any case, with tar, or cpio, you may want to carefully examine the
options to determine which you do, and don't wish to include.
Seems the primary issue you were running into, is if your current
working directory remains in the directory containing
dir1/dir2/RAWdirectory, then when you create an archive of
RAWdirectory, e.g. via cpio or tar, that archive would also contain
dir1/dir2 above RAWdirectory, and hence that structure would normally
be reproduced when extracted from the archive. By changing directory
to that above RAWdirectory before creating the archive, we eliminate
the problem of including dir1/dir2 in the archive above RAWdirectory.
There may be other ways of doing this with copy (copy isn't installed
on
anything that's presently up and running and at my fingertips).
writetosmacky@gmail.com wrote:
> I am trying to copy some specific directories over to another
> directory, using the find and cpio or copy commands. I am working in a
> directory that is two directories above the directories that I need to
> copy (I have to copy multiple directories within different
> directories). Each dir structure looks like this:
> data(my working directory)
> |
> dir1
> |
> dir2
> |
> RAWdirectory(and contents)that-I-need-to-copy
> I tried doing this:
> find . -name '*RAW' -depth -print | cpio -pdumv target_dir/
> and I also tried this:
> find ././* -name '*RAW*' -depth -print | cpio -pdumv target_dir/
> These commands will copy the directories I need to the target
> directory, but ALSO copy the two directories above each RAW directory,
> which I do not want to copy. Does anyone know how to copy directories
> that are *inside* other directories *without* copying the directories
> that they are nested in?
|
|
|
|
|