0

I am using this script to mv all the files from a shared directory to another directory:

cd /share
while :
do
  for allfiles in $(find /share/ -maxdepth 1 -type f -iname "*" -mmin +1);
do
  sudo mv "$allfiles" /schoolstore/
  done
  sleep 15s
done

But, I get error when a filen contains a space within its name, where can I fix the script to get it to work for all files name?

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255

1 Answers1

0

Based on the other question referenced in my comment here is my suggestion (not tested)

cd /share

do
  for allfiles in $(find /share/ -maxdepth 1 -type f -iname "*" -mmin +1);
  do
    aveIFS="$IFS"; IFS=''; ls $file; 
    sudo mv "$allfiles" /schoolstore/
    IFS="$saveIFS"
  done

There are probably ways to optimize it, and I removed the while part of your code since it seems like that would not halt.

Needless to say, backup all your files before running this type of code (or any code for that matter).

Alternatively, instead of changing $IFS it might be possible to to this operation only with one find command using the -exec flag. Here is what I mean (again, untested):

find /share/ -maxdepth 1 -type f -iname "*" -mmin +1 -exec mv {} /schoolstore/ \;
jsb
  • 281