Saturday, March 24, 2018

Copy specific files from within nested folders

I had a situation where I needed to save all log files that were present in nested sub-folders and copy them over to another folder for analysis.
There are many ways to do this - but here is the simplest that I could figure out using rsync:
rsync -aihv --include='*/' --include='*.log*' --exclude='*' /source_folder/to/search/in/  /destination_folder/to/copy/to/

Important thing to note here is the order of include and exclude flags passed to rsync command - it is sensitive to the order in which these flags are provided.
First include flag '*/' makes rsync look into subfolders and the second flag selects all files of the format '*.log*'.
The next exclude flag excludes any file not selected as yet and then copies them over to the destination folder.
You can provide more include flags before the exclude flag to select multiple types of files as per your requirement.


Anonymous said...

want to have the real pleasure come to san jose escorts

tejaswini said...

I have bookmarked your site since this site contains significant data in it. I am extremely content with articles quality and introduction. You rock for keeping incredible stuff. I am a lot of appreciative for this site.360DigiTMG pmp certification in malaysia

360DigiTMG said...

It is the expect to give noteworthy information and best takes a shot at, including a perception of the regulatory cycle.what is hrdf

360DigiTMG said...

I see the best substance on your blog and I unbelievably love getting them.

hrdf claimable training said...

Thankful to you for putting aside the push to convey this information important!
hrdf claimable training

360digitmg said...

This is a wonderful article, Given so much info in it, These type of articles keeps the users interest in the website, and keep on sharing more ... good luck.
data science training in hyderabad


Related Posts Plugin for WordPress, Blogger...