I have 1000 files grouped in a single directory. And I need to store each file in their own directory.

I'm looking for a solution to create 1000 directories with the same naming as the files and also move the files in to their own directory.

Thanks in advance!


1 Answer 1


I am happy to tell you that this is a relatively simple thing to accomplish:

for f in *.* ; do (mkdir -p new/$f && cp $f new/$f/ ) ; done

This will place a folder with the same name as the file in the "new" folder location and copy the file in question there. If they are large files and this would take some time, I suggest you include an "echo" statement in the one-liner to show where you are at.

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.