Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I want to place a list of files into individual directories I create from each filename. So given the files in the root directory:

Movie1.avi
movie2.m4v
movie3.mp4

I want to mkdir Movie1, movie2, and movie3, then move each file into the corresponding directory.

Any simple way to to generate the directories and then move the files.

mkdir << find /Video/Movies/ -maxdepth 1 -type f | sort
mv << find /Video/Movies/ -maxdepth 1 -type f | sort
share|improve this question

marked as duplicate by Ярослав Рахматуллин, Tog, Scott, Nifle, Randolph West Oct 3 '13 at 18:55

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
The command at the end of the question is never explicitly referenced in the question. Is it not working? Do you want a better command? –  inixsoftware Sep 27 '13 at 23:52

2 Answers 2

You could define this function and use it with a wildcard...

movetofolder(){
for F in $@; do 
    FOLDER=${F%.*}
    mkdir "$FOLDER"
    mv "$F" "$FOLDER"
done
}

Usage: movetofolder *ovie*

share|improve this answer

This should work...

mkdir container && find . -maxdepth 1 -type f -exec mkdir ./container/{} \; -exec mv {} ./container/{}/ \; -exec mv ./container/{} ./ \; && rm -r container

share|improve this answer

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