Operating System - HP-UX
1832483 Members
2568 Online
110043 Solutions
New Discussion

Re: I want to copy a directory, but not all the files

 
Jos de Ruiter
Advisor

I want to copy a directory, but not all the files

Hi,

I want to copy a directory to a other directoy, but not all the files. There ar about 2000 files.

I now the option cp -p -r directory > directory.

Who can help me!!!
Jos de Ruiter
11 REPLIES 11
Vibhor Kumar Agarwal
Esteemed Contributor

Re: I want to copy a directory, but not all the files

You can try something like:

find . -name xyz -type d -exec mkdir -p /destination/ {} \;

here you can have xyz as the child node to make it in one step.
Vibhor Kumar Agarwal
Muthukumar_5
Honored Contributor

Re: I want to copy a directory, but not all the files

You can try as,


cd
find . \( ! -name . \) -type d -exec cp -r {} / \;

or

cd
find . \( ! -name . \) -type d | xargs cp -r

Also refer to,
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=898151

hth.
Easy to suggest when don't know about the problem!
Jos de Ruiter
Advisor

Re: I want to copy a directory, but not all the files

Thanks for the reply.

Can i use a exclude file???
Jos de Ruiter
Vibhor Kumar Agarwal
Esteemed Contributor

Re: I want to copy a directory, but not all the files

You can use one more switch of find.

find . -name "file_to_exclude" -prune

In addition to the above this will leave this file only.

If there are some more try the or option.
-o
Vibhor Kumar Agarwal
Cem Tugrul
Esteemed Contributor

Re: I want to copy a directory, but not all the files

How About this ?

cd source_dir
for direct in `ls -lrt|grep "^d"|awk '{print $9}'`
do
cp $direct targer_dir
done

Good Luck,
Our greatest duty in this life is to help others. And please, if you can't
A. Clay Stephenson
Acclaimed Contributor

Re: I want to copy a directory, but not all the files

You might actually find it easier to use fbackup piped to frecover. Fbackup can write to stdout and frecover can read from stdin so
fbackup | frecover works very well. A graph file for fbackup lets you specify both the includes and the excludes. Man fbackup, frecover for details.
If it ain't broke, I can fix that.
Leif Halvarsson_2
Honored Contributor

Re: I want to copy a directory, but not all the files

Hi,

I have sometimes used the method, first creating a list of files with find, then edit the list and last, reading the list from a script which copies the files.

By the way, it is very common to use cpio together with find for copying files.

find . |cpio -pdvmux
Jos de Ruiter
Advisor

Re: I want to copy a directory, but not all the files

hi Leif,

I use your command, but to make first een file.index with "find . > file.index" en edit this one is ok.

But now a try to used it in your command.
"cat file.index |cpio -pdvmux /data" this seems to be working

I try to remove *.TCP from the file.index with a script command, so i can a create a sort of exclude file??.

Groet, Jos.


Jos de Ruiter
Eknath
Trusted Contributor

Re: I want to copy a directory, but not all the files

Hi Jos,

How about using fbackup where you can specify list of files to be included or excluded, Check man pages of fbackup for more info.

Cheers !!!
eknath
Cem Tugrul
Esteemed Contributor

Re: I want to copy a directory, but not all the files

i am sending these notes because both
A.Clay Stephenson & Eknath's suggestions
also are significant for me and at once
i thought these notes would be helpful to you

Good luck,
FBACKUP/FRECOVER

Things to remember about fbackup:

* fbackup MUST rewind the tape before beginning the backup and after
completing.
* a tape created with fbackup is only recoverable with frecover.
* a file listed in the index file (from option -rvNf) is not guaranteed
to be on the tape; this simply means that fbackup intended to back the
file up when it began the backup session.

Command Description

fbackup -vf /dev/rmt/0m -i / full system backup

fbackup -vf /dev/rmt/0m -i specifically include file/directory
/etc/hosts preceded by -i

fbackup -vf /dev/rmt/0m -i specifically include multiple
/etc/hosts -i /usr files/directories preceded by -i

fbackup -vf /dev/rmt/0m -e specifically exclude file/directory
/etc/hosts preceded by -e

fbackup -vf /dev/rmt/0m -g
graph_file_name backup from a graph file

frecover -xvf /dev/rmt/0m restore entire tape to originating
directory structure

restore entire tape to originating
frecover -xovf /dev/rmt/0m directory structure and overwrite any
existing files

cd /tmp restore entire tape to /tmp
frecover -xXvf /dev/rmt/0m (originating directory structure will
not be overwritten)

frecover -vf /dev/rmt/0m -I verify backup and read the index file
/tmp/index from the tape into a file called
/tmp/index

fbackup -vf /dev/rmt/0m 2>&1 log what is backed up, along with any
|tee /tmp/backup.log errors that occur

frecover -rNv -f /dev/rmt/0m 2>
/tmp/listing list of what is really on the tape

frecover -V /tmp/volume_headers
-f /dev/rmt/0m show volume headers on the tape
Our greatest duty in this life is to help others. And please, if you can't
Jos de Ruiter
Advisor

Re: I want to copy a directory, but not all the files

HI,

I want to thanks all de members who have reply, I try several optie from everyone.

Thanks, Jos.
Jos de Ruiter