Beta
×

Welcome to the Slashdot Beta site -- learn more here. Use the link in the footer or click here to return to the Classic version of Slashdot.

Thank you!

Before you choose to head back to the Classic look of the site, we'd appreciate it if you share your thoughts on the Beta; your feedback is what drives our ongoing development.

Beta is different and we value you taking the time to try it out. Please take a look at the changes we've made in Beta and  learn more about it. Thanks for reading, and for making the site better!

shell script to distribute files from 1 dir to many dirs

mrflash818 (226638) writes | more than 4 years ago

User Journal 0

Just a shell script I wrote to be able to distribute files in one file to many directories.
Created it because my one directory of digital images was getting too big, such that it was slowing down image viewer startup.

distributeFiles.sh
***
#! /bin/bash

Just a shell script I wrote to be able to distribute files in one file to many directories.
Created it because my one directory of digital images was getting too big, such that it was slowing down image viewer startup.

distributeFiles.sh
***
#! /bin/bash

#
# distribte (by using mv)files from a source directory
# to collection of target directories (by using a for loop)
#
# distributeFiles.sh ...
#
if [ "$#" -lt "3" ]
then
    echo "distributeFiles.sh ... "
    exit
fi

ARG_ARRAY=( "$@" )
SOURCE_DIR=${ARG_ARRAY[0]}
#echo "SOURCE_DIR[$SOURCE_DIR]"

unset ARG_ARRAY[0]
#for i in "${ARG_ARRAY[@]}"
#do
# echo $i
#done

ARG_ARRAY_LENGTH=${#ARG_ARRAY[@]}
#echo "ARG_ARRAY LENGTH is $ARG_ARRAY_LENGTH"

AAL=1
#
# Get list of files to distribute
#
for i in $(ls $SOURCE_DIR)
do
    if [ -d "$SOURCE_DIR/$i" ]
    then
        continue
    fi
    #distribute to the distination directories
    #echo "mv \"${SOURCE_DIR}/$i\" ${ARG_ARRAY[$AAL]}/."
    mv ${SOURCE_DIR}/$i ${ARG_ARRAY[$AAL]}/.
    AAL=$((AAL + 1))
    if [ $AAL -gt $ARG_ARRAY_LENGTH ]
    then
        AAL=1
    fi
done
***

Sorry! There are no comments related to the filter you selected.

Check for New Comments
Slashdot Login

Need an Account?

Forgot your password?