Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

3
  • for f in *.; do name=echo "$f"|sed 's/ -.*//' letter=echo "$name"|cut -c1 dir="DestinationDirectory/$letter/$name" mkdir -p "$dir" mv "$f" "$dir" done Commented Nov 1, 2017 at 18:34
  • I think I need to use a for loop but im not sure how to do it in bash Commented Nov 1, 2017 at 18:37
  • 1
    Neither cut nor sed know that apples are fruits or chocolates are sweets, so you need a mechanism to relate the files to the directories. Commented Nov 2, 2017 at 9:16