Created
January 13, 2020 12:20
-
-
Save f-steff/05079a2efdc67cbfacfbda0ad0aba9aa to your computer and use it in GitHub Desktop.
Bash shell: Sort sets of numbered files into numbered Folders
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # I had 70000+ files all named after the pattern nnn_something.jpg. nnn was a number from 000 to 999. Not all numbers existed. | |
| # Each set of nnn belonged together, and I wanted them placed in sub-folders like this 074/074_something.jpg | |
| # These three bash shell commands cleaned up the mess in a few seconds: | |
| # CREATE FOLDERS. | |
| #This works on bash prior to version 4 - as on Mac. (Newer Bash can just write $ mkdir {000..999} ) | |
| $ for i in 00{0..9} 0{10..99} {100..999}; do mkdir ${i} ; done | |
| # MOVE FILES | |
| #This works on bash prior to version 4 - as on Mac. (Newer Bash can use {000..999} ) | |
| $ for i in 00{0..9} 0{10..99} {100..999}; do mv ${i}*.jpg ${i}/ ; done | |
| # DELETE EMPTY FOLDERS | |
| $ find . -type d -empty -delete |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment