Ask Different is a question and answer site for power users of Apple hardware and software. 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've been looking for answer on the web now for a few hours and can't find what im looking for. What i want to do is move each file in a directory to a new folder using the name of the file, excluding the extension.

/Movies/Filname.avi ---> /Movies/Filename/Filename.avi

I know how to do each individual file, but can i do it reclusively for the whole folder using one command or a script.

share|improve this question
Can you please post your script as an answer instead of adding it to the question? Would make it easier to other users to understand what's going on. – patrix Feb 18 '14 at 8:57

This should do the trick.

shopt -s nullglob    #avoid problems in directory with no files
ext=avi              #the file extension to search for
for f in *.$ext; do
    d="${f##/}"      #gives us just the filename
    d="${d%.$ext}"   #strips the file extension
    mkdir "$d"       #makes the directory
    mv "$f" "$d/$f"  #moves the file
share|improve this answer
In the end I decided to write my own, not bad only that i have multiple extensions. I'll post my script in a few hours, when I am allowed – moosethemucha Feb 18 '14 at 6:42

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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