2

I'd like to move all sub-folders starting with a given suffix (Blah_ in the example) into an other directory using a linux bash script. Here's what the script looks like:

srcDir="/home/me/"
archiveDir="/Archive/"
prefix="Blah_"
mv -v -f "$srcDir$prefix*" -t $archiveDir

Though there are a lot of directories starting with 'Blah_', inside /home/me, this leads to the following error message:

mv: cannot stat `/home/me/Blah_*': No such file or directory

Now I'm curious whats wrong here. How must the above script be changed in order to move all subfolders starting with 'Blah' into the archive folder?

Tolaksa
  • 165
  • 1
  • 1
  • 6

2 Answers2

3
mv -v -f ${srcDir}${prefix}* -t $archiveDir

in this case if you quote, * will be interpreted literally

johnshen64
  • 5,747
  • 23
  • 17
1

How about:

find   /home/me   -type   d   -name   "Blah_*"   -exec   mv   -i  {}  /Archive \;
quanta
  • 50,327
  • 19
  • 152
  • 213
DisgruntledUser
  • 101
  • 2
  • 9