copy files from directory to directory without subfile
Hi there,
Is there any method in bash to do the following: I want to copy all the file and subdirectories of a directory "exept" a directory called sub_abc. Is this possible ?? |
Hi,
This should do the trick: find /home/user -type d \! -path './*/sub_abc*' -exec cp -R {} /path/to/destination/ \; Don't know how much experience you have with find, so here's a breakdown of the command. /home/user : search starts here -type d \! -path './*/sub_abc*' : return directories only (-type d) except (\!) if the path has sub_abc in it (-path './*/sub_abc*') You will end up with all the dirs except the directory that is called sub_abc. -exec cp -R {} /path/to/destination/ \; This will exectue a cp -R. The found paths are put between {} the destination is /path/to/destination. Don't forget the \; A Few Notes: Try the first part of the command before using the -exec part, especially if you're new to this stuff. Something like: find /home/user -type d \! -path './*/sub_abc*' -exec echo "cp -R {} /path/to/destination/" \; will do nothing but show what it would do. Or, simpler: find . -type d \! -path './*/sub_abc*' prints what it finds. |
I want to copy the file like in cp , isnt there a simpler method
|
All times are GMT -5. The time now is 10:33 PM. |