Search code examples
linuxmove

How can I move multiple folders that contain specific word in the name to another directory in linux?


I have a directory Dir in which I have about 30 sub-directories. From these 30 sub-dirs there are about 20 with name dir_date and the other 10 with some random names. I want to move all the directories that contain dir in their names to another directory which could be created under Dir using the command line. I am using CentOS 5.7


Solution

  • In a terminal, you can simply do

    mv *dir* /example/location
    

    where dir is a pattern that matches anything containing "dir". Fix the pattern to match your needs.

    This will move all files containing "dir" in the directory you are in (in terminal, type pwd to check your current directory).