Reputation: 1541
I have a folder, which consists of many folders and many tar files. (this many is around 1000)
I want to write a script to copy all folders with their contents to another directory, but I do not want to copy tar files.
I already know by writing
cp -a /source/ /path/
I can copy a directory with its contents to another, but for this case, I do not know how to do it.
As the number of directories are alot, I am not able to each time copy one directory.
I appreciate if someone can help me on this.
Upvotes: 0
Views: 199
Reputation: 784958
You can combine cp
in find
to exclude *.tar
files:
dest='/path/'
mkdir "$dest" &&
find /source -mindepth 1 -not -name '*.tar' -exec cp -a {} "$dest" \;
Upvotes: 1
Reputation: 490
I think this might be what you're looking for.
You want to use the rsync
command and in the --exclude
flag you want to put *.tar
So your answer will look something like this:
rsync -r --exclude='*.tar' [source] [destination]
This is also a helpful little tutorial on how to use rsync
.
Upvotes: 1