XCOPY Alternative in UNIX

Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jul 2006
Posts: 59
Reputation: Shane_Warne is an unknown quantity at this point 
Solved Threads: 0
Shane_Warne Shane_Warne is offline Offline
Junior Poster in Training

XCOPY Alternative in UNIX

 
1
  #1
Aug 8th, 2006
Hi all,
Can you please tell me if there is a bash command in UNIX that is similar in functionality to XCOPY in Windows? XCOPY can copy who directory trees from a source folder to a destination folder, but from what I saw about the cp command in bash, it is not possible. Also XCOPy can copy only new files, and returns if files were copied or not. I would like if the bash command did that as well. Here is the XCOPY functional specs for further reference. You can find if files had been copied or not by looking at the XCOPY return codes.

Thanks in advance.
Shane
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 5,051
Reputation: John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold 
Solved Threads: 332
Team Colleague
John A's Avatar
John A John A is offline Offline
Vampirical Lurker

Re: XCOPY Alternative in UNIX

 
1
  #2
Aug 8th, 2006
Obviously you haven't looked very carefully at the man page.
Copying directory trees (recursive mode):
cp -r
Copying directory trees, viewing all files copied (verbose mode):
cp -rv

You can string any of the cp options together, like that.
http://linux.about.com/od/commands/l/blcmdl1_cp.htm
"Technological progress is like an axe in the hands of a pathological criminal."

All my posts may be freely redistributed under the terms of the MIT license.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 59
Reputation: Shane_Warne is an unknown quantity at this point 
Solved Threads: 0
Shane_Warne Shane_Warne is offline Offline
Junior Poster in Training

Re: XCOPY Alternative in UNIX

 
1
  #3
Aug 9th, 2006
oh. sorry I missed something in my question. I wanted to selectively copy the files in the source directory into the destination directory. Say for example all the .h files and .c files. XCOPY can do this by using the /S switch.

Shell Scripting Syntax (Toggle Plain Text)
  1. SomeFolder
  2. |
  3. +--Source
  4. |
  5. +--Dest
if you type
Shell Scripting Syntax (Toggle Plain Text)
  1. XCOPY /S *.h ..\dest
it will recursively copy the .h files in source to dest while retaining the directory structure.

I tried it with cp but it didnt do that.
Shell Scripting Syntax (Toggle Plain Text)
  1. $ cp -R *.h ../temp
  2. cp: cannot stat `*.h': No such file or directory
  3.  
Is there any way i can do that in bash?
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 5,051
Reputation: John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold 
Solved Threads: 332
Team Colleague
John A's Avatar
John A John A is offline Offline
Vampirical Lurker

Re: XCOPY Alternative in UNIX

 
0
  #4
Aug 9th, 2006
Shell Scripting Syntax (Toggle Plain Text)
  1. $ cp -R *.h ../temp
  2. cp: cannot stat `*.h': No such file or directory
  3.  
You need a path. You can't just put "*.h". You need either to use working directories, or the full path:
cp -r somefolder/*.h ../someotherfolder
"Technological progress is like an axe in the hands of a pathological criminal."

All my posts may be freely redistributed under the terms of the MIT license.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 59
Reputation: Shane_Warne is an unknown quantity at this point 
Solved Threads: 0
Shane_Warne Shane_Warne is offline Offline
Junior Poster in Training

Re: XCOPY Alternative in UNIX

 
1
  #5
Sep 8th, 2006
I am afraid that doesn't work. Only the files in the somefolder is copied to the destination. Recursive seraching is not done. Can you please try the above command and see if my observation is correct.
Create a folder like this.

Shell Scripting Syntax (Toggle Plain Text)
  1. ├─dest
  2. └─source
  3. │--test1.h
  4. └─child
  5. └─test2.h
The above command


Shell Scripting Syntax (Toggle Plain Text)
  1. cp -r source/*.h dest
doesnt copy the test2.h file in the child directory. Only the test1.h is copied.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,580
Reputation: Infarction has a spectacular aura about Infarction has a spectacular aura about Infarction has a spectacular aura about 
Solved Threads: 52
Infarction's Avatar
Infarction Infarction is offline Offline
Battle Programmer

Re: XCOPY Alternative in UNIX

 
1
  #6
Sep 9th, 2006
The reason cp -r source/*.h is not working is because you've only told it to look at .h files. For that reason, it doesn't copy the child directory (since it's not a .h file itself), much less its contents (though they may be .h files).
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 59
Reputation: Shane_Warne is an unknown quantity at this point 
Solved Threads: 0
Shane_Warne Shane_Warne is offline Offline
Junior Poster in Training

Re: XCOPY Alternative in UNIX

 
1
  #7
Sep 9th, 2006
So how do I tell to look for .h files in child folders as well? I want to copy them so that the directory structure is the same as the source directory structure. I hope you understand what I am trying to do here. I only want the shell command please. I have looked the documentation of cp and tried all combinations. So if you know the exact answer please reply.
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 178
Reputation: jim mcnamara is on a distinguished road 
Solved Threads: 10
jim mcnamara jim mcnamara is offline Offline
Junior Poster

Re: XCOPY Alternative in UNIX

 
1
  #8
Sep 11th, 2006
Shell Scripting Syntax (Toggle Plain Text)
  1. #!/bin/bash
  2. # we want to copy from path1 to path2
  3. # step 1 make all the subdirectories
  4. find /path1 -type d | \
  5. while read dir
  6. do
  7. mkdir /path2"${dir#/path1}"
  8. done
  9. # step 2 cp the files
  10. find /path1 -type f | \
  11. while read $file
  12. do
  13. cp "$file" /path2"${file#/path1}"
  14. done
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 30
Reputation: sut is an unknown quantity at this point 
Solved Threads: 1
sut sut is offline Offline
Light Poster

Re: XCOPY Alternative in UNIX

 
1
  #9
Sep 11th, 2006
Shell Scripting Syntax (Toggle Plain Text)
  1. tar -cvf - $(find . -name "*.h") | (cd ../dest ; tar -xvf -)
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 1
Reputation: bianxi is an unknown quantity at this point 
Solved Threads: 0
bianxi bianxi is offline Offline
Newbie Poster

Re: XCOPY Alternative in UNIX

 
0
  #10
Jun 18th, 2009
find . -name "*.h" -print0 | cpio --null -pvd new-dir
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Shell Scripting Forum


Views: 7191 | Replies: 9
Thread Tools Search this Thread



Tag cloud for Shell Scripting
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC