0

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

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

2
  • That certainly works but there are literally thousands of files with lots of different names. My hope was the script could search names it deems have similar names and generate a folder based on that name. – deadbunneh Mar 10 '20 at 14:22
  • You can always append the command, so if you have a file named 13M0nster you can use "mv Mster Monster/". – Ecstasy Mar 10 '20 at 14:39
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

2
  • 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. – deadbunneh Mar 12 '20 at 12:44
  • the tricky part is the identification of similar names. This is why I suggested to do it manually, any algorithm will probably has its strong and weak points. I wish you success.... – ruud Mar 12 '20 at 13:34
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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