Skip to content

Instantly share code, notes, and snippets.

@EndruK
Created October 30, 2020 16:57
Show Gist options
  • Save EndruK/449c60aca90f875a83754820edcc47e8 to your computer and use it in GitHub Desktop.
Save EndruK/449c60aca90f875a83754820edcc47e8 to your computer and use it in GitHub Desktop.
copy files from one directory to another based on a file selection list with rsync
#!/bin/bash
# Script Usage
# create a file holding only the names of files / folders to copy
#
# ls -A1 > file_selection.txt
#
# remove all lines which should not be copied
#
# move to the folder where the files are and run the script:
#
# cd /dir/where/files/are
# bash /path/to/copy_files.sh /path/to/file_selection.txt /target/path
filename=$1
target=$2
IFS=$'\n'
for line in $(cat $filename)
do
file_path=$(readlink -f $line)
echo "copy $file_path to $target"
/usr/bin/rsync -r --progress $file_path $target
done < "$filename"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment