Recursively Moving Files

Recursively Moving Files

Several times I've run into the situation where I have 30 or more files within 30 or more folders and I want to move them all into one location. I always flounder around and have to do some Google searching to figure out how. It's really simple, and this will serve as my own notepad so I can quickly find it again later.

Essentially, you just find all the files and then run a command against that list. It's actually easy to do from a command line, but a bit archaic. Here's an example:

find ./ -type f -name '*.txt' -exec mv -i {} ./ \;

That command will find all txt files in subdirectories of the current working directory and move them all into the current directory. Easy peasy!

Posted by Tony on Jan 24, 2018 | Linux Tricks