Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 was marked as an exact duplicate of an existing 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

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 .