0

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.

Kadaj13
  • 1,423
  • 3
  • 17
  • 41

2 Answers2

1

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.

Sal Alturaigi
  • 480
  • 1
  • 7
  • 15
1

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" \;
anubhava
  • 761,203
  • 64
  • 569
  • 643