Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
    
Remove the quotes –  Zoredache Aug 8 '12 at 21:08

2 Answers 2

up vote 3 down vote accepted
mv -v -f ${srcDir}${prefix}* -t $archiveDir

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

share|improve this answer
    
Perfect! Thank you very much! –  Tolaksa Aug 8 '12 at 21:33

How about:

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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