Skip to content
Advertisement

Copying folders but not tar files in linux

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.

Advertisement

Answer

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.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement