Issue
I want to exclude two directories while copying.
Example:
$ ls /root/tmp
a b c d e f
I want to exclude directories a
and b
:
$ cp -rp /root/tmp/ /root/tmp1/
Solution
You could exclude the directories as part of find results before the copy, but using rsync
or cp
with the '!'
support enabled as suggested by Sathiya is a much simpler solution.
See find
example below:
find /root/tmp/ -mindepth 1 -maxdepth 1 -type d ! -regex '\(.*a\|.*b\)' -exec cp -r {} /root/tmp1/ \;
Answered By - Pieter de Bruin