| | |
XCOPY Alternative in UNIX
Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jul 2006
Posts: 59
Reputation:
Solved Threads: 0
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
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
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
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.
All my posts may be freely redistributed under the terms of the MIT license.
•
•
Join Date: Jul 2006
Posts: 59
Reputation:
Solved Threads: 0
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.
if you type
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.
Is there any way i can do that in bash?
Shell Scripting Syntax (Toggle Plain Text)
SomeFolder | +--Source | +--Dest
Shell Scripting Syntax (Toggle Plain Text)
XCOPY /S *.h ..\dest
I tried it with cp but it didnt do that.
Shell Scripting Syntax (Toggle Plain Text)
$ cp -R *.h ../temp cp: cannot stat `*.h': No such file or directory
•
•
•
•
Shell Scripting Syntax (Toggle Plain Text)
$ cp -R *.h ../temp cp: cannot stat `*.h': No such file or directory
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.
All my posts may be freely redistributed under the terms of the MIT license.
•
•
Join Date: Jul 2006
Posts: 59
Reputation:
Solved Threads: 0
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.
The above command
doesnt copy the test2.h file in the child directory. Only the test1.h is copied.
Create a folder like this.
Shell Scripting Syntax (Toggle Plain Text)
├─dest └─source │--test1.h │ └─child └─test2.h
Shell Scripting Syntax (Toggle Plain Text)
cp -r source/*.h dest
•
•
Join Date: Jul 2006
Posts: 59
Reputation:
Solved Threads: 0
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.
•
•
Join Date: May 2004
Posts: 178
Reputation:
Solved Threads: 10
Shell Scripting Syntax (Toggle Plain Text)
#!/bin/bash # we want to copy from path1 to path2 # step 1 make all the subdirectories find /path1 -type d | \ while read dir do mkdir /path2"${dir#/path1}" done # step 2 cp the files find /path1 -type f | \ while read $file do cp "$file" /path2"${file#/path1}" done
•
•
Join Date: Sep 2006
Posts: 30
Reputation:
Solved Threads: 1
Shell Scripting Syntax (Toggle Plain Text)
tar -cvf - $(find . -name "*.h") | (cd ../dest ; tar -xvf -)
![]() |
Similar Threads
- unix download? (*nix Software)
Other Threads in the Shell Scripting Forum
- Previous Thread: Shell Script That Acts Like Dos
- Next Thread: Replacing a Line feed with a new line itself.
Views: 7191 | Replies: 9
| Thread Tools | Search this Thread |
Tag cloud for Shell Scripting






