Friday, September 20, 2013

[Linux] - Copy and exclude certain folder

Let say you have a folder structure like below:
  • source
    • folder_video
      • videoA.mpg
      • videoB.mpg
      • videoC.mpg
    • folder_contents
      • file1.txt
      • file2.txt
    • folder_picture
    • fileA.txt
    • fileB.txt
    • folder_documents
     
You want to copy all contents on the source folder and at the same time exclude certain folder. How? Follow the below instruction.

Exclude single folder

rsync -avz --exclude folder_video /source /your_destination_path

* it will copy the source folder to your_destination_path and exclude the folder_video

Exclude multiple folder

rsync -avz --exclude folder_video --exclude folder_contents /source /your_destination_path

* it will copy the source folder to your_destination_path and exclude the folder_video and folder_contents

Exclude file and folder at a same time

rsync -avz --exclude folder_video --exclude folder_contents/file1.txt /source /your_destination_path

* it will copy the source folder to your_destination_path and exclude the folder_video and file1.txt