Created
October 23, 2017 10:39
-
-
Save Pk13055/f01fe1fa5a020431dfdc89d5dbd645e1 to your computer and use it in GitHub Desktop.
Copy multiple files or directories to multiple locations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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[@]}) |
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
Multi File copier script
This script enables you to copy multiple files/directories from multiple sources to multiple locations.
How to Run
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)