Site Map - skip to main content

Hacker Public Radio

Your ideas, projects, opinions - podcasted.

New episodes every weekday Monday through Friday.
This page was generated by The HPR Robot at


hpr4373 :: Rsync with stdin as source

Use find pipe it's the results into rsync to make a copy.

<< First, < Previous, , Latest >>

Hosted by oxo on Wednesday, 2025-05-07 is flagged as Explicit and is released under a CC-BY-SA license.
bash, commandline, find, rsync, pipe, stdout, stdin, backup, copy. 3.

Listen in ogg, opus, or mp3 format. Play now:

Duration: 00:20:13
Download the transcription and subtitles.

Bash Scripting.

This is an open series in which Hacker Public Radio Listeners can share their Bash scripting knowledge and experience with the community. General programming topics and Bash commands are explored along with some tutorials for the complete novice.

In today's show, oxo show us how you can use the output of the find command with -print0 option to rsync files to another location.


find . -type f -mmin -230 -print0 | rsync -aAXv --info=progress2,stats --progress --from0 --files-from - . dst


Comments

Subscribe to the comments RSS feed.

Comment #1 posted on 2025-05-09 10:05:17 by Paulj

rsync capabilities

Hi Oxo - Thanks for the show.

One question - Doesn't rsync only copy the files which have changed in the source or destination directory? In other words, you wouldn't need the "find ..." part of the command. Or did you only want to transfer new changes, and older changes are not to be transferred across?
I use rsync for keeping my server music up to date. I have a local copy of my music (ripped from CDs I actually own!!), and have an instance of Jellyfin running on a server. I mount the server music directory on my local machine, and run:

rsync -avt --delete /var/lib/mpd/music/ /mnt/music/

This copies files from my local directory into the mounted folder, and deletes any files in the latter which are not in the former. If I understand your show, you are working to achieve the same thing - have a master copy on one machine, and update the directories on other machines.
I like the -print0 option - I haven't seen that before, and it looks useful.

I look forward to your next episode!

Comment #2 posted on 2025-05-09 16:13:32 by archer72

Rsync - paulj

That sounds like a great setup.
Are there details you can share in a show?

I am cautious of --delete because of nearly lost data of my child's younger pictures and the day after her birth video. Of course my backup strategy was not great either. I ended up using testdisk (or photoRec?) It has been a while, and I'm sadly lacking documentation.

https://www.cgsecurity.org

Comment #3 posted on 2025-05-17 20:12:33 by Dave Morriss

Enjoyable show!

Thanks for this.

I liked your "stream of consciousness" approach to making a show. It was good to follow along with your thoughts.

Yes, I agree with Paulj that 'rsync' is all about updating the destination with differences detected in the source, so the 'find' seems redundant.

However, it's interesting to examine the '-print0' option. I have used it when I have files with spaces (and other weirdnesses) in their names, which I need to process. Many other commands accept null-terminated names, so this can be very useful.

Here's a case in an HPR script I wrote a long time ago when I was a "Janitor":

mapfile -d '' -t pix < \
<(find "$SHOWDIR" -maxdepth 1 -regextype egrep -regex '.*\.(jpg|JPG|png|PNG)' -print0 |\
sort -z)

It fills an array 'pix' with picture file names, avoiding problems with spaces in names (hopefully anyway!).

The "null" characters generated by find are non-printable, but you could save the output and view it with an editor, or with 'od' or 'cat -v' to "see" them.

You mentioned 'ACL'. This stands for Access Control List, a POSIX feature which gives more fine-grained access control to filesystem objects.

Looking forward to more shows like this :-)

Leave Comment

Note to Verbose Commenters
If you can't fit everything you want to say in the comment below then you really should record a response show instead.

Note to Spammers
All comments are moderated. All links are checked by humans. We strip out all html. Feel free to record a show about yourself, or your industry, or any other topic we may find interesting. We also check shows for spam :).

Provide feedback
Your Name/Handle:
Title:
Comment:
Anti Spam Question: What does the letter P in HPR stand for?