In a project I am working on, I originally had some directory named assets, with a large number of directories, whose names are not predictable, each of these directories contained a number of files, whose names were the same for each directory (but with different content). My original file-structure would look something like this:
assets | |-some_dir | |-blue.txt | |-apple.txt | |-red.txt | |-banana.txt | |-some_other_dir | |-blue.txt | |-apple.txt | |-red.txt | |-banana.txt ... |-yet_another_dir | |-blue.txt | |-apple.txt | |-red.txt | |-banana.txt
Obviously, the files and directories don't have these exact names. I want to introduce a new file structure, such that the files stay in the same directories, but are put within other directories within these directories: ie. I want:
assets | |-some_dir | |-colors | | |-blue.txt | | |-red.txt | |-fruits | | |-apple.txt | | |-banana.txt | |-some_other_dir | |-colors | | |-blue.txt | | |-red.txt | |-fruits | | |-apple.txt | | |-banana.txt ... |-yet_another_dir | |-colors | | |-blue.txt | | |-red.txt | |-fruits | | |-apple.txt | | |-banana.txt
There are so many directories in assets, that going through each by hand is not an option, so I want to do this in one, or at least very few shell-commands (I am on zsh by the way).
I am able to create the subdirectories inside each directory, using the reply to this question but I can not figure out how to move the files into the new directory, keeping in mind that each file shall only be moved to the directory inside the directory it is in already.
Edit: since this is not clear: I am willing to move each of the files (per name) individually to sort them correctly (there are only a handful of files per directory) but I will not repeat this for each individual directory
mv blue.txt colors/) inside every single directory; and I am assuming that such an automated way already exists, so I did not think that I was asking for a new tool.