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:

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?

  • Remove the quotes – Zoredache Aug 8 '12 at 21:08
mv -v -f ${srcDir}${prefix}* -t $archiveDir

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

|improve this answer|||||

How about:

find   /home/me   -type   d   -name   "Blah_*"   -exec   mv   -i  {}  /Archive \;
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.