LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-11-2007, 02:03 AM   #1
ovince
Member
 
Registered: Mar 2007
Posts: 77

Rep: Reputation: 15
copy


hi,


I am trying to make a short script to copy files, whole tree structures ... This is how I started

###3 copyTree - cp tree structure: copyTree "*.dat" "*.txt" "C:/...."
Code:
function copyTree() {

if [ $# = 2 ]
    then
    	find -depth -name "$1" -print0 | cpio --null -pvd $2
    elif [ $# = 3 ]
    then
    	find -depth -name "$1" -name "$2" -print0 | cpio --null -pvd $2
    elif [ $# = 4 ]
    then
    	find -depth -name "$1" -name "$2" -name "$3" -print0 | cpio --null -pvd $2	
fi		

}
It works when I use it like

copyTree "*.dat" "C:/...."

but not works when trying

copyTree "*.dat" "*.txt" "C:/...."

Why?

thanks
 
Old 06-11-2007, 03:31 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

If you want to use more then one -name option with find you need to add the -o (OR) option. I.e:

find -depth -name "$1" -o -name "$2" -print0

or

find -depth \( -name "$1" -o -name "$2" \) -print0

BTW: The first example will not always work, the second will.

Hope this helps.
 
Old 06-11-2007, 10:07 AM   #3
ovince
Member
 
Registered: Mar 2007
Posts: 77

Original Poster
Rep: Reputation: 15
I tried bot suggestion

Code:
###3 copyTree - cp tree structure:  copyTree "*.*" "C:/...." 
function copyTree() {

if [ $# = 2 ]
    then
    	find -depth -name "$1" -print0 | cpio --null -pvd $2
    elif [ $# = 3 ]
    then
    	#find -depth \( -name "$1" -o -name "$2" \) -print0 | cpio --null -pvd $2
    	find -depth -name "$1" -o -name "$2" -print0 | cpio --null -pvd $2
    elif [ $# = 4 ]
    then
    	find -depth \( -name "$1" -o -name "$2" -o -name "$3" \) -print0 | cpio --null -pvd $2	
fi		

#find -depth -name "$1" -print0 | cpio --null -pvd $2

}
does not work...do you know why
 
Old 06-11-2007, 10:31 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

I see another typo/mistake in your script:

find -depth -name "$1" -o -name "$2" -print0 | cpio --null -pvd $2

Should be:

find -depth -name "$1" -o -name "$2" -print0 | cpio --null -pvd $3

And the find..cpio line below that should end with $4 instead of $2.

Hope this helps.
 
Old 06-11-2007, 10:42 AM   #5
ovince
Member
 
Registered: Mar 2007
Posts: 77

Original Poster
Rep: Reputation: 15
true ... you are very good observer
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
CLI copy is greater than GUI copy ?? 0_o killahsmurf Slackware 14 01-04-2006 11:53 AM
how to copy and paste acd copy cd paschim Linux - General 2 04-05-2004 09:25 AM
boot error after using Copy Commander to copy debian system onto larger new drive Interceptor Linux - Hardware 7 05-04-2003 12:40 PM
HELP: i cant copy from CD bkxsammy Linux - General 20 12-11-2002 08:30 PM
how to copy a cd safrout Linux - General 6 05-08-2002 10:29 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:20 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration