Exclude Sub-Directories while Copying (cp) Files / Directory using tar

I recently had the need to copy a directory to another portion of the file system, but wanted to skip some sub-directories. Normally what one would do is just copy the whole directory and delete the sub-directories that you don’t want after the copy operation has completed (and not make a big deal about it). However that wasn’t feasible this time, because each of these sub-directories had GBs of data and I did not have enough disk space to accomodate those extra files. I went through the cp man page and did a few google searches but did not find anything that would work for me. However I realized that I had just used the “exclude” feature of tar a few days back which lets you skip portions of a directory while tarring and I knew tar could be used to copy over files as well (tar pipe). So thats what I did. Continue reading