1

Wonder if anyone can help..bit of a noob and I've found partial answers online but nothing specific.

I'm using OSX 10.11

I have a folder with a LOT of older artwork files and would like to use Terminal or a script to place files of a similar or same name into a folder together with the same name.

EG:
FOLDER: ALL
Monster1
Cat colours
Monster Prelims
Girl coloured
Girl2
Monster 2
Cat sketch
Monster with colours
Cat finalised
Monster final

Would end up like this:

FOLDER: MONSTER
Monster1
Monster 2
Monster Prelims
Monster final
Monster with colours

FOLDER: GIRL
Girl coloured
Girl2

FOLDER:CAT
Cat sketch
Cat finalised
Cat colours

3 Answers3

0

You could just do it like this:
mkdir Monster
mv Monster* Monster/ (move everything that starts with "Monster" into Monster/)

Then repeat the same commands with different files/folders

Ecstasy
  • 392
0

If I had this problem I would first create a file with prefixes by doing ls -1 | sort > prefixes, edit the prefixes file and manually deleting the file names and replacing it with the proper prefixes. Then I would use that one to do a move like ecstasy proposed for all prefixes.

So the prefixes file would first read

Cat colours
Cat finalised
Cat sketch
Cows
Girl coloured
Girl2
Monster 2
Monster Prelims
Monster final
Monster with colours
Monster1

And be saved containing

Cat
Girl
Monster

(I added a Cows line that is not to be put in a subfolder) Then with the proper shell syntax this can be processed, for example in zsh with

for h in `cat prefixes`
do
  mkdir $h
  mv $h* $h
done

Hope this helps, Ruud

ruud
  • 153
0

Thanks for your suggestion. I think this method will still be too time-consuming. The folder in question probably has around 7k files in it.

What I really need is something that

• Checks all names of files in folder

• Identifies when several files have the same or similar name

e.g. it will select super-hero.jpeg super-hero5.psd AND super-girl.png

• It will then create a folder based upon this identified recurring name

• Moves the selected files to said folder

I’m assuming this may be impossible, but will keep trying.