1

Is there a means of using rsync to sync two folders?

I would like to shoot photos in JPG and RAW. Since viewing JPGs is much quicker than opening up RAWs, I'd like to do culling in the JPG folder and then sync it to the RAW folder. However they contain different extensions but the same file name.

I realize that the most likely solution is to create a sh to accomplish this and then give it an alias.

2
  • 2
    Can you clarify what you are asking? Are you asking us to write a script for you? Have you tried anything? How did it go? What do you still need? Is this for Linux? macOS? BSD? Everything? Please edit your question and give us more details.
    – terdon
    May 13 at 11:02
  • Apologies, this is intended to be used on MacOS, but I submitted it under Unix/Linux because I know I can use it in bash across Linux / Unix also. I read the entire manual for rsync (really wordy) but didn't see anything like what I was looking for. Haven't written a script for Bash before, but just wanted to know that I hadn't overlooked something. Was planning on posting the solution here regardless. Going to give BiG_NoBoDy's solution a run here and report back :) May 13 at 19:25

1 Answer 1

0

in general, if you have similar filename that changes in some particular place, you can set those differences in [] brackets:

ruslanas@ruslanas test]$ ls 
a.jpg  a.raw  a.doc
[ruslanas@ruslanas test]$ ls a.{jpg,raw}
a.jpg  a.raw
[ruslanas@ruslanas test]$ 

or just use asterisk if you have only jpg and raw extension and only those 2 extensions.

also, if you would like to use a singleliner to extract jpg from raw and then move raw to raw dir:

cd /path/to/fresh-photos && ls *raw | while read line ; do culling $line -output /path/to/processed/jpg/$(echo $line | sed 's/raw$/jpg/g') && mv $line /path/to/processed/raw ; done

just replace culling with your cooler and should be good to go!

Also disadvantage of previous line, that you have to have temp dir for new files... Also there is a simple way to make it only do culling to non processed jpg's:

RAW=/path/to/raw && JPG=/path/to/jpg && find $RAW $JPG -type f \( -name '*.raw' -o -name '*.jpg' \) -exec basename {} \; | sed -e 's/\.jpg$//g' -e 's/\.raw$//g' | sort -n | uniq -u | while read line ; do echo "processing ${RAW}/${line}.raw" && culling ${line}.raw -output ${JPG}/$line.jpg ; done

Again, replace culling with our cuddling command.

If you need just remove photos from RAW which are not present in JPG dir:

RAW=/path/to/raw && JPG=/path/to/jpg && find $RAW $JPG -type f \( -name '*.raw' -o -name '*.jpg' \) -exec basename {} \; | sed -e 's/\.jpg$//g' -e 's/\.raw$//g' | sort -n | uniq -u | while read line ; do echo "Removing: ${RAW}/${line}.raw" && rm -f ${RAW}/${line}.raw ; done

keep in mind all extensions expected to be lowercase, if not change to what is in your side.

Before first release, run this test command:

RAW=/path/to/raw && JPG=/path/to/jpg && find $RAW $JPG -type f \( -name '*.raw' -o -name '*.jpg' \) -exec basename {} \; | sed -e 's/\.jpg$//g' -e 's/\.raw$//g' | sort -n | uniq -u | while read line ; do echo "Removing: ${RAW}/${line}.raw" && echo rm -f ${RAW}/${line}.raw ; done

Also, if you will be putting it into script.bash file, then replace && and ; with enters/new lines. For more readable text.

4
  • Thanks for the tip on the search. I didn't realize you could regex the extension. Maybe I need to update the original question. I have the JPGs in one folder, and RAWs in another. I want to only keep files in the RAW folder with the same name in the JPG folder (those which haven't been deleted). This feels like it does a bit more? (Sorry still learning bash) May 13 at 19:59
  • Oh, so you want to delete raw files that were deleted in jpg dir? Did I understood it correctly?
    – BiG_NoBoDy
    May 15 at 8:09
  • Yes, that's the objective May 20 at 2:28
  • updated @Sparatan117
    – BiG_NoBoDy
    2 days ago

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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