Satyam Mishra
Satyam Mishra

Reputation: 11

Need to move files locally using rsync in bash script

can you please help me on below files having spaces in name are not copying need some help.

rsync \
  -avhs \
  --protect-args \
  --remove-source-files \
  --info=progress2 \
  `find $sourcepath -daystart -mtime 2 -type f` \
  $bavkuppath

Upvotes: 1

Views: 133

Answers (1)

Charles Duffy
Charles Duffy

Reputation: 295363

Assuming you want all the filenames substituted into your command line exactly the same way that command substitution would do it --

#!/usr/bin/env bash
#              ^^^^ this MUST be run with bash, not sh

# obvs, fill these in with your real locations
sourcepath=/some/where
bavkuppath=/else/where

readarray -d '' sourcepaths < <(
  find "$sourcepath" -daystart -mtime 2 -type f -print0
)
rsync \
  -avhs \
  --protect-args \
  --remove-source-files \
  --info=progress2 \
  "${sourcepaths[@]}" \
  "$bavkuppath"

It may be better, however, to tell rsync to read the list of paths to copy from a file, and have that file be a process expansion written by find. In this case, your command would look like:

rsync \
  -avhs \
  --protect-args \
  --remove-source-files \
  --info=progress2 \
  --from0 \
  --files-from <(find "$sourcepath" -daystart -mtime 2 -type f -print0) \
  "$bavkuppath"

Upvotes: 1

Related Questions