I want to copy all files in a directory except some files in a specific sub-directory. I have noticed that 'cp' command didn't have a --exclude option. So, how can I achieve this?
相关问题
- Is shmid returned by shmget() unique across proces
- how to get running process information in java?
- Error building gcc 4.8.3 from source: libstdc++.so
- Why should we check WIFEXITED after wait in order
- Null-terminated string, opening file for reading
rsync
and first try it with -n option to see what is going to be copied
This is a modification of Linus Kleen's answer. His answer didn't work for me because there would be a . added in front of the file path which cp doesn't like (the path would look like source/.destination/file).
This command worked for me:
find . -type f -not -path '*/exlude-path/*' -exec cp --parents '{}' '/destination/' \;
the --parents command preserves the directory structure.
I assume you're using bash or dash. Would this work?
Doing an ls excluding the files you don't want, and using that as the first argument for cp
One way would be to use
find -0
with-prune
to find all the files and directories you want to move, then usexargs -0
to copy each one.It's relative to the source directory.
This will exclude the directory
source/.git
from being copied.