mv folder that match pattern

command-line-interface, linux, move

Solution

You can use directly `mv` command to move as follows

 mv *BBC* newfolder1

And

 mv *peppapig* newfolder2

You can also do something like this using `find`

 find . -type d -name '*BBC*' -exec mv "{}" newfolder1 \;

And

 find . -type d -name '*peppapig*' -exec mv "{}" newfolder2 \;

Problem

I have hundreds of folders to organize according to the folder's name, let's say I have few folders that has name BBC and peppapig as the part of the name e.g. (folders) ``` doc_BBC_life BBC.nature peppapigepisode1 kidspeppapigseries animalsBBC-docment newfolder1 newfolder2 ``` Now I want to move folders (there are four) that has the name "BBC" into the subfolder called newfolder1 and same goes for the folder that has the name "peppapig" into newfolder2 folder Note: each folder has several files that also has the name either "BBC" or "peppapig", I want to maintain the contents without scrambling around. I want to do something like this "mv BBC BBC/ Any suggestion using mv? thanks

Original source