Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a server set up that receives movies to a folder. I then serve these movies using DLNA. But in the initial folder where they end up all kind of files end up. Pictures, music, documents etc. I thought I'd fix this by running the following script inside that folder

rsync -rvt --include='*/' --include='*.avi' --include='*.mkv' --exclude='*' . ../Movies/

This works and scans the given folder and moves all the found movies of the given extension types to the Movies folder.

But I wonder if there is anyway to tell rsync to if a folder if found that includes a movie of the given extension types, sync the entire folder. Including other files such as .srt. This is to make it easier for me to get subtitles moved along with the movie.

I have a solution figured out via a script made in php (yea, I actually do most of my scripting in linux using php... just a habbit that stuck a long time ago). But if rsync can handle it from the start that would be super.

Also, I have noticed that this line of rsync actually copies all the root folders in the given folder. If no movie is in the folder it will create an empty folder. How do I prevent rsync from doing this... and saving me the trouble of deleting all folder in Movies that are empty.

share|improve this question

I'm highly confident that you need to use some sort of external script wrapped around rsync to make that happen. Thus, the ultimate answer to your question is a succinct, "No."

share|improve this answer

Going by your path examples above with your source files being in "." and you want them copied to "../Movies":

if [ `find . -name \*.avi | wc -l` -gt 1 ]; then rsync ./ ../Movies/; fi
share|improve this answer
Every time an AVI file is found, rsync is executed on the working directory... So the first time it finds one, it syncs, and then the other 10,000 times rsync runs again... – Jeff Ferland Dec 29 '10 at 18:42

Why don't you sync everythink not only movies (*) . If all data is synced - rsync will do nothing, if some new files appear (i.e. subtitels or movies) - they will be synced

share|improve this answer
yea, but in this folder all kinds of stuff end up. Torrent client downloads to this folder, documents might end up here etc. I don't want all of this to be synced to the Movies folder. – inquam Dec 29 '10 at 19:55
up vote 0 down vote accepted

Not nice but I ended up using the rsync option and then running find -type d -empty -delete to get rid of all the empty folders

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.