Skip to content

Instantly share code, notes, and snippets.

@Pk13055
Created October 23, 2017 10:39
Show Gist options
  • Save Pk13055/f01fe1fa5a020431dfdc89d5dbd645e1 to your computer and use it in GitHub Desktop.
Save Pk13055/f01fe1fa5a020431dfdc89d5dbd645e1 to your computer and use it in GitHub Desktop.
Copy multiple files or directories to multiple locations
#!/bin/bash
k=0
l=0
flag=1
files=()
locs=()
for i in $@
do
if [ "$i" = "," ]
then
flag=0
continue
fi
if [ $flag -eq 1 ]
then
files+=($i)
else
locs+=($i)
fi
done
echo ${locs[@]} | xargs -n 1 cp -rv $(echo ${files[@]})
@Pk13055
Copy link
Author

Pk13055 commented Oct 23, 2017

Multi File copier script

This script enables you to copy multiple files/directories from multiple sources to multiple locations.

How to Run

  • Download the script.
  • chmod 755 multi-cp.sh
  • ./multi-cp.sh [file/dir1 file/dir2 ...] , [loc1 loc2 loc3 ...]
    (Additionally, you can sudo mv multi-cp.sh /usr/bin/multi-cp to have this script available globally)

@ParthKolekar
Copy link

You might want to look at IFS in bash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment